我创建了navigationController项目名称:autoload, 然后创建两个名为uiviewContorller的名称:second,three
i create i navigationController project name:autoload, then create two uiviewContorller named: second,three
我想让进程加载rootView方法中的第二个加载方法:"viewDidLoad",然后在方法"viewdidload"中自动加载三个方法, 这是代码:
i want the process is load rootView the load second in method:"viewDidLoad" then auto load three in method"viewdidload", here is the code:
rootView:
- (void)viewDidLoad { self.title = @"first"; Second *second = [[Second alloc] init]; AutoLoadAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; [delegate.navigationController pushViewController:second animated:YES]; [super viewDidLoad]; }秒:
- (void)viewDidLoad { self.title = @"second"; [super viewDidLoad]; }现在构建一个程序,我可以自动加载到第二个非常正确的位置 包括标题内容和导航按钮
now build an go the program, i can auto load to second very correct includeing the title content and also the navgation button
然后我想在第二秒内加载aotoload,所以在第二种方法中添加代码:"viewdidload"
then i want aotoload three in second,so add the code in second method:"viewdidload"
秒:
- (void)viewDidLoad { self.title = @"second"; **Three *three = [[Three alloc] init]; AutoLoadAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; [delegate.navigationController pushViewController:three animated:YES];** [super viewDidLoad]; }最后将标题添加到三个:
finaly add the title to three:
三个:
- (void)viewDidLoad { self.title = @"three"; [super viewDidLoad]; }然后构建并运行,您会发现内容正确的是三个" 但是标题错误的是第二",应该是三个" 而且您还会发现导航按钮是错误的
then build and go, you will find that the content is right "three" but the title is wrong "second", it should be "three" and you will also find the navgation button is wrong
我的那是什么错,我应该怎么做才能实现自动加载到三个的程序?
what's wrong with my that,what i should do to implement the program of autoload to three?
注意:
我尝试: 如果我第二秒钟添加一个按钮并移动代码
i try that : if i add a button in second and move the code
Three *three = [[Three alloc] init]; AutoLoadAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; [delegate.navigationController pushViewController:three animated:YES];对于ibaction,它将是正确的工作,但我希望它自动加载
to the ibaction ,it will be work correct, but i want it load automaticly
推荐答案而不是在viewDidLoad方法中调用pushViewController,请尝试在applicationDidFinishLaunching方法中设置viewControllers数组:
Instead of calling pushViewController in the viewDidLoad methods, try setting the viewControllers array in the applicationDidFinishLaunching method:
- (void)applicationDidFinishLaunching:(UIApplication *)application { RootViewController *root = [[RootViewController alloc] init]; root.title = @"root"; Second *second = [[Second alloc] init]; second.title = @"second"; Three *three = [[Three alloc] init]; three.title = @"three"; [navigationController setViewControllers:[NSArray arrayWithObjects:root,second,three,nil] animated:YES]; [root release]; [second release]; [three release]; [window addSubview:[navigationController view]]; [window makeKeyAndVisible]; }更多推荐
iPhone NavigationController自动加载到三个级别
发布评论