UITabBarController 加载子视图
我有点陷入困境,希望对我做错了什么有任何想法。 我以编程方式创建了一个 NSObject,它包含一个 UITabBarController,其中添加了三个 ViewController:
UITabBarController tabBarController = [[UITabBarController alloc] init];
ControllerOne = [[OneViewController alloc] initWithNibName:@"OneView" bundle:nil];
ControllerTwo = [[TwoViewController alloc]initWithNibName:@"TwoView" bundle:nil];
ControllerThree = [[ThreeViewController alloc] initWithNibName:@"ThreeView" bundle:nil];
NSMutableArray *viewControllers = [[NSMutableArray alloc] initWithCapacity:3];
[viewControllers addObject:ControllerOne];
[viewControllers addObject:ControllerTwo];
[viewControllers addObject:ControllerThree];
[tabBarController setViewControllers:viewControllers];'
我现在显示 tabBarController 的视图
viewController.modalTransitionStyle = transitionStyle;
[self presentModalViewController:viewController animated:YES];
,其中 viewController 是刚刚创建的 tabBarController。 视图变化良好,正确显示选项卡栏(图标和标题),但无法显示例如 OneViewController 的视图。我假设视图未加载,因为没有为任何子视图控制器调用 - (void)viewDidLoad
。
我将不胜感激任何建议。
谢谢, 等
I am kind of stuck and would appreciate any ideas on what I did wrong.
I created programmatically a NSObject which holds a UITabBarController to which three ViewControllers are added:
UITabBarController tabBarController = [[UITabBarController alloc] init];
ControllerOne = [[OneViewController alloc] initWithNibName:@"OneView" bundle:nil];
ControllerTwo = [[TwoViewController alloc]initWithNibName:@"TwoView" bundle:nil];
ControllerThree = [[ThreeViewController alloc] initWithNibName:@"ThreeView" bundle:nil];
NSMutableArray *viewControllers = [[NSMutableArray alloc] initWithCapacity:3];
[viewControllers addObject:ControllerOne];
[viewControllers addObject:ControllerTwo];
[viewControllers addObject:ControllerThree];
[tabBarController setViewControllers:viewControllers];'
I now display the tabBarController's view
viewController.modalTransitionStyle = transitionStyle;
[self presentModalViewController:viewController animated:YES];
with viewController being the just created tabBarController.
The view changes fine, displaying the tabbar correctly (Icons and titles) but fails to show e.g. OneViewController's view. I assume that the view is not loaded since the - (void)viewDidLoad
is not being called for any of the subview controllers.
I would appreciate any suggestions.
Thanks,
equi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定您的笔尖名称就是您输入的名称吗?例如,它不叫 OneViewController.xib?
Are you sure your nib names are how you have typed them? It's not called OneViewController.xib?, for example?
我解决了这个问题。
上面的代码实际上有效,视图没有出现的原因是我不小心在 UIViewController 派生中合成了“视图”。
I sorted out the issue.
The above code actually worked, reason for the view not appearing was that I accidentally synthesised 'view' in the UIViewController derivative.