简体   繁体   English

XCode5 self.navigationController pushViewController:animated:不会打开新的viewcontroller

[英]XCode5 self.navigationController pushViewController:animated: doesn't open the new viewcontroller

I'm not sure why but in Xcode 5 working on a project of IOS6.1 I have a button connected to a IBAction in which I'm trying to navigate to a new view controller. 我不确定为什么,但是在处理IOS6.1项目的Xcode 5中,我有一个连接到IBAction的按钮,我正在其中尝试导航到新的视图控制器。

I've tried two different codes to create the viewController and then push it to the navigation in both cases the view controller is not nil and both cases the viewController doesn't appear. 我尝试了两种不同的代码来创建viewController,然后在两种情况下视图控制器都不为零并且两种情况下均未出现viewController时将其推入导航。

first try: with story Id - I've set the story id of the view controller to imageCapture and set the class to VSImageCaptureViewController 首先尝试:使用故事ID-我已将视图控制器的故事ID设置为imageCapture,并将该类设置为VSImageCaptureViewController

VSImageCaptureViewController* imageCaptureViewController = (VSImageCaptureViewController*)([self.storyboard instantiateViewControllerWithIdentifier:@"imageCapture"]);

[self presentViewController:imageCaptureViewController animated:NO completion:nil];

second try: with the name of the viewcontroller 第二次尝试:使用ViewController的名称

VSImageCaptureViewController *imageCaptureViewController = [[VSImageCaptureViewController alloc] initWithNibName:@"VSImageCaptureViewController" bundle:nil];

[self.navigationController pushViewController:imageCaptureViewController animated:YES]; 

can you see something wrong or do you think I forgot to initialize something 你能看到错误的东西吗?还是我忘了初始化一些东西?

Check to see if self.navigationController is nil. 检查self.navigationController是否为nil。

If it is nil that means that you are not running within the context of a UINavigationController (the system sets this property for you when the UIViewController is added to a nav stack). 如果为nil,则表示您不在UINavigationController的上下文中运行(将UIViewController添加到导航堆栈时,系统会为您设置此属性)。

If this is the case then you have not properly set up a UINavigationController. 如果是这种情况,则您没有正确设置UINavigationController。

Note that you can not set the navigationController property yourself. 请注意,您不能自己设置navigationController属性。 The systems sets it for you when the UIViewController is added to a UINavigationController's stack (and sets it to nil when it is removed from the stack). 当将UIViewController添加到UINavigationController的堆栈时,系统会为您设置它(将其从堆栈中删除时将其设置为nil)。

To set this up you will usually create a UINavigationController instance right after you create your main view controller. 要进行设置,通常会在创建主视图控制器之后立即创建一个UINavigationController实例。

UIViewController *mainViewController = ...;
UINavigationController *mainNavController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
// now present the mainNavController instead of the mainViewController

If you are using storyboards you would drag out a UINavigationController instance and replace the default root view controller with an instance of your mainViewController. 如果使用情节提要,您将拖出一个UINavigationController实例,并用mainViewController的实例替换默认的根视图控制器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IOS 5 Crash @ [self.navigationController pushViewController:vcSummary animated:YES]; - IOS 5 Crash @ [self.navigationController pushViewController:vcSummary animated:YES ]; self.navigationController pushViewController 不工作 - self.navigationController pushViewController not working self.navigationController pushViewController未将控制器添加到堆栈 - self.navigationController pushViewController not adding controller to stack 由于self.navigationController为null,pushviewcontroller无法正常工作 - pushviewcontroller not working because self.navigationController is null UITableView [self.navigationController pushViewController:Page1 animation:YES]; 方法不起作用 - UITableView [self.navigationController pushViewController:Page1 animated:YES]; method not working iOS / iPhone didSelectRowAtIndexPath self.navigationController pushViewController不起作用 - iOS/iPhone didSelectRowAtIndexPath self.navigationController pushViewController not working self.navigationcontroller 推送没有导航项的视图控制器 - self.navigationcontroller pushs viewcontroller without navigation item iOS-[self.navigationController setToolbarHidden:YES动画:NO]崩溃 - iOS - Crash on [self.navigationController setToolbarHidden:YES animated:NO] Deallocated error self.navigationController ==无 - self.navigationController == nil self.navigationController为null - self.navigationController is null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM