从 viewDidLoad 加载视图控制器
您好,我想使用 X 代码在 iPhone 中创建一个选项卡栏应用程序。我有一个启动屏幕,然后我有我的主屏幕,我想在该视图中创建选项卡栏。 因此,我在 ViewDidLoad 方法中创建了一个选项卡栏。
- (void)viewDidLoad {
NSLog(@"in Home");
tabBarController = [[UITabBarController alloc] init];
homeViewController = [[HomeViewController alloc]init];
NextViewController = [[NextViewController alloc]init];
tabBarController.viewControllers = [NSArray arrayWithObjects:homeViewController,nextViewController,nil];
window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
[super viewDidLoad];
}
现在当我编译& 运行,它会再次调用HomeView& 再次,当我点击第二个选项卡时,它不会调用 NextView。
那么,这段代码有什么问题请帮助我..
Hello I want to create a tabbar application in iPhone using X-code.I have one splash screen and then after that I have my Home Screen where I want to create tabbar in that view. so, I create a tabbar in my ViewDidLoad method.
- (void)viewDidLoad {
NSLog(@"in Home");
tabBarController = [[UITabBarController alloc] init];
homeViewController = [[HomeViewController alloc]init];
NextViewController = [[NextViewController alloc]init];
tabBarController.viewControllers = [NSArray arrayWithObjects:homeViewController,nextViewController,nil];
window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
[super viewDidLoad];
}
Now when I compile & Run, It will call the HomeView again & again and when I tap on 2nd tab it will not call the NextView.
So, what is wrong in this code Plz help me..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为 viewDidLoad 位于 homeViewController 中,所以您不是一次又一次地添加 homeViewController 吗?
Aren't you adding the homeViewController again and again since viewDidLoad is in homeViewController...
我是否可以建议您从
Tab Bar Application
模板启动一个新项目,只是为了看看它在正确情况下是如何完成的? 您甚至可以保留它并在其中改装您的启动屏幕。Can I recommend that you start a new project from the
Tab Bar Application
template just to look at how it's done when it's done right? You might even keep that and retrofit your splash screen into it.