Due to I have to slide UIViewController from left to right by a finger swipe, I have created a custom uiviewcontroller transition, after slide and clicked the navigation inside the destination controller, error occurred.
Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'stepsPage'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
- (void) returnHome
{
UIStoryboard *storyboard = self.storyboard;
MainViewController *destVC = [storyboard instantiateViewControllerWithIdentifier:@"main"];
// Get the views.
UIView * toView = destVC.view;
UIView * fromView = self.view;
// Get the size of the view area.
CGRect viewSize = fromView.frame;
// Add the toView to the fromView
[fromView.superview addSubview:toView];
// Position it off screen.
toView.frame = CGRectMake( -320 , viewSize.origin.y, 320, viewSize.size.height);
NSLog(@" viewSize.origin.y %f", viewSize.size.height);
[UIView animateWithDuration:0.3 animations:
^{
// Animate the views on and off the screen. This will appear to slide.
fromView.frame =CGRectMake( 320 , viewSize.origin.y, 320, viewSize.size.height);
toView.frame =CGRectMake(0, viewSize.origin.y, 320, viewSize.size.height);
}
completion:^(BOOL finished)
{
if (finished)
{
// Remove the old view from its parent.
[fromView removeFromSuperview];
//I use it to have navigationnBar and TabBar at the same time
//self.tabBarController.selectedIndex = indexPath.row+1;
}
}];
NSLog(@"swipe");
}
Segue Function in the destination view controller
- (void) prepareForSegue: (UIStoryboardSegue *) segue sender: (id) sender
{
GeneralViewController *GeneralView = (GeneralViewController*)segue.destinationViewController;
NSString *titleString;
// Set the photo if it navigates to the PhotoView
if ([segue.identifier isEqualToString:@"stepsPage"])
{
titleString = @"Steps";
GeneralView.goalStr = [NSString stringWithFormat:@"%d", [mySetting integerForKey:@"dailyStep"]];
GeneralView.currentStr = [NSString stringWithString:_stepLabel.text];
GeneralView.percentage = grpPercent.step;
}
else
{
return;
}
}