由于我必须通过手指滑动从左向右滑动UIViewController,我创建了一个自定义uiviewcontroller转换,在幻灯片后单击目标控制器内的导航,发生错误。
由于未捕获的异常'NSGenericException'而终止应用, 原因:'找不到segue'stepsPage'的导航控制器。 Push segues只能在管理源控制器时使用 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功能
- (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;
}
}
答案 0 :(得分:2)
错误,你得到的控制器周围没有导航控制器,你想把它推到下一个控制器
以下方法可适用于此类情况
方法1 - 直观地添加导航控制器
您需要将第一个控制器或现有控制器嵌入到UINavigation中
控制器 - 你可以通过转到编辑器在xcode 5中完成 - > EmbedIn - >选择导航控制器
如果您不希望导航显示在您的应用中,可以使用下面的行
self.navigationController.navigationBar.hidden =YES;
方法2 - 以编程方式添加导航控制器
如果你想以编程方式进行,你可以按照以下方式进行:
MainViewController *destVC = [storyboard instantiateViewControllerWithIdentifier:@"main"];
UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:destVC];