UITabBarController 加载子视图

发布于 2024-11-01 09:37:33 字数 1109 浏览 0 评论 0原文

我有点陷入困境,希望对我做错了什么有任何想法。 我以编程方式创建了一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

像你 2024-11-08 09:37:33

您确定您的笔尖名称就是您输入的名称吗?例如,它不叫 OneViewController.xib?

Are you sure your nib names are how you have typed them? It's not called OneViewController.xib?, for example?

棒棒糖 2024-11-08 09:37:33

我解决了这个问题。
上面的代码实际上有效,视图没有出现的原因是我不小心在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文