i wanted to implement an optional protocol for my subviews. the subview-class is inherited by uiviewcontroller and the most viewcontrollers are inherited by this subview. i think it is a simple structure.
the problem is: it only works in the simulator. on a device just the first nslog appears, then the application closes. on the simulator it works fine.
what could it be ?
sure you see, that some things are commented out, but they dont have any effort.
the protocol:
@protocol CustomGestures <NSObject>
@optional
-(void)nextPage;
-(void)previousPage;
@end
parts of my subviewcontroller
@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");
}
}
}
}
parts of a subview
@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]
}