I have a storyboard with 2 scenes. Each scene has a segue ctrl+dragged from ViewController icon to the other scene. Segue from first view to the second has identifier "left" and from the second to the first - "right", both Segues point to the same custom class inherited from UIStoryboardSegue. Each ViewControllers has a title in Attribute Inspector, and don't have any custom classes assigned to them just yet.
In AppDelegate I have UISwipeGestureRecognizer setup for all 4 directions and according to how user swipes if the current view controller has a segue with identifier "left", "right", "up", or "down" it fires performSegueWithIdentifier:
- (void) handleSwipe:(UISwipeGestureRecognizer *) recognizer {
NSString *direction;
switch ([recognizer direction]) {
case UISwipeGestureRecognizerDirectionLeft:
direction = @"left";
break;
case UISwipeGestureRecognizerDirectionUp:
direction = @"up";
break;
case UISwipeGestureRecognizerDirectionDown:
direction = @"down";
break;
default:
direction = @"right";
break;
}
@try {
UIViewController *rootVC = self.window.rootViewController;
[rootVC performSegueWithIdentifier:direction sender:rootVC];
} @catch (NSException *e) {
NSLog(@"Segue with identifier <%@> does not exist", direction);
}
}
In my custom Segue class I override the "perform" method as follows (nothing fancy, since it breaks as is, but naturally I override it to be able to have a custom animation for segues later):
-(void) perform {
UIViewController *src = (UIViewController *) self.sourceViewController;
UIViewController *dst = (UIViewController *) self.destinationViewController;
NSLog(@"source: %@, destination: %@", src.title, dst.title);
[src presentModalViewController:dst animated:NO];
}
However, it only works once on the first swipe to the left and after that nothing happens. I can see via the NSLog in the "perform" method that segue's source and destination view controllers don't change for some reason after this first transition and just stay the same onward. It looks like I am missing something simple, but I can't figure it out.
Don't be too harsh on me ;) , I am new to the iOS development.