サブビューにオプションのプロトコルを実装したかったのです。サブビュー クラスは uiviewcontroller によって継承され、ほとんどのビュー コントローラーはこのサブビューによって継承されます。シンプルな構造だと思います。
問題は、シミュレーターでのみ機能することです。デバイスでは、最初の nslog だけが表示され、その後アプリケーションが閉じます。シミュレーターでは正常に動作します。
どうなり得るか ?
確かに、コメントアウトされているものもありますが、それらには何の努力もありません。
プロトコル:
@protocol CustomGestures <NSObject>
@optional
-(void)nextPage;
-(void)previousPage;
@end
サブビューコントローラーの一部
@implementation SubViewController
//handles gestures and passes them
//further to the superclass
//uiviwcontroller to take the normal behaviour
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
//pass the information to superclass
[super touchesEnded:touches withEvent:event];
//create object with protocol and some other objects
id<CustomGestures> gestures;
UITouch* touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self.view];
CGFloat deltaX = gestureStartPoint.x - currentPosition.x;
CGFloat deltaY = fabs(gestureStartPoint.y - currentPosition.y);
//if the subclass (self) has the protocol implemented, use the protocoll-features
if ([self conformsToProtocol:@protocol(CustomGestures)])
{
if (deltaX <= -80 && deltaY <= 20) {
NSLog(@"vorige seite");
[gestures nextPage];
} else
if (deltaX >= 80 && deltaY <= 20) {
[gestures previousPage];
NSLog(@"nächste seite");
}
}
}
}
サブビューの一部
@interface NavInfos :
SubViewController <CustomGestures>{
....}
@implementation NavInfos
//CustomGestures-Protocol
-(void)nextPage{
NSLog(@"nächste seite im navinfos");
//[[TTNavigator navigator] openURLAction:[TTURLAction actionWithURLPath:@"tt://mapkit"]];//applyAnimated:YES]
}
-(void)previousPage{
NSLog(@"vorige seite im navinfos");
//[[TTNavigator navigator] openURLAction:[TTURLAction actionWithURLPath:@"tt://windows"]];
//applyTransition:UIViewAnimationTransitionFlipFromLeft] applyAnimated:YES]
}