我想为我的子视图实现一个可选协议。子视图类由 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]
}