问题描述
我创建了一个 navigationController 项目名称:自动加载,然后创建两个 uiviewContorller 命名为:second,three
i create i navigationController project name:autoload,then create two uiviewContorller named: second,three
我希望进程是在方法viewDidLoad"中加载rootView加载第二个然后在方法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:
根视图:
- (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];
}
现在构建一个 go 程序,我可以自动加载到第二个非常正确包括标题内容和导航按钮
now build an go the program, i can auto load to second very correctincludeing the title content and also the navgation button
然后我想在秒内自动加载三个,所以在第二种方法中添加代码: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];
}
然后build然后去,你会发现内容是对的三"但是标题错了二",应该是三"而且你还会发现导航按钮不对
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 自动加载到三级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!