UITabBarController 的 setTitle 在 iOS 5 中超过 5 个项目时崩溃?
在将我的 Xcode 从 4.1 更新到 4.2 之前,以下代码在 iOS 4.3 上运行良好,但是在升级 Xcode 并在使用 iOS 5 的 iPhone 上测试我的应用程序后,它在启动时不断崩溃!
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:tabController.view];
[[tabController.tabBar.items objectAtIndex:0] setTitle:@"Tab1"];
[[tabController.tabBar.items objectAtIndex:1] setTitle:@"Tab2"];
[[tabController.tabBar.items objectAtIndex:2] setTitle:@"Tab3"];
[[tabController.tabBar.items objectAtIndex:3] setTitle:@"Tab4"];
[[tabController.tabBar.items objectAtIndex:4] setTitle:@"Tab5"];
[[tabController.tabBar.items objectAtIndex:5] setTitle:@"Tab6"];
[[tabController.tabBar.items objectAtIndex:6] setTitle:@"Tab7"];
[[tabController.tabBar.items objectAtIndex:7] setTitle:@"Tab8"];
[[tabController.tabBar.items objectAtIndex:8] setTitle:@"Tab9"];
[self.window makeKeyAndVisible];
return YES;
}
它会抛出以下错误:
2011-10-15 15:13:31.238 Mobile[2347:707] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 5 beyond bounds [0 .. 4]'
*** First throw call stack:
(0x311138bf 0x382b81e5 0x3106b275 0x336b 0x330e57eb 0x330df3bd 0x330ad921 0x330ad3bf 0x330acd2d 0x33c98e13 0x310e7553 0x310e74f5 0x310e6343 0x310694dd 0x310693a5 0x330de457 0x330db743 0x2acd 0x2a28)
如果我只保留前 5 个 setTitle,它将起作用,但如果它超过 5 个,它将崩溃!
请注意,我不是以编程方式在 IB 中创建 UITabBarController。
Before updating my Xcode from 4.1 to 4.2 the following was code was working fine with iOS 4.3, but after upgrading Xcode and test my app on iPhone with iOS 5 it keep crashing on startup!
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:tabController.view];
[[tabController.tabBar.items objectAtIndex:0] setTitle:@"Tab1"];
[[tabController.tabBar.items objectAtIndex:1] setTitle:@"Tab2"];
[[tabController.tabBar.items objectAtIndex:2] setTitle:@"Tab3"];
[[tabController.tabBar.items objectAtIndex:3] setTitle:@"Tab4"];
[[tabController.tabBar.items objectAtIndex:4] setTitle:@"Tab5"];
[[tabController.tabBar.items objectAtIndex:5] setTitle:@"Tab6"];
[[tabController.tabBar.items objectAtIndex:6] setTitle:@"Tab7"];
[[tabController.tabBar.items objectAtIndex:7] setTitle:@"Tab8"];
[[tabController.tabBar.items objectAtIndex:8] setTitle:@"Tab9"];
[self.window makeKeyAndVisible];
return YES;
}
It throws the following error:
2011-10-15 15:13:31.238 Mobile[2347:707] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 5 beyond bounds [0 .. 4]'
*** First throw call stack:
(0x311138bf 0x382b81e5 0x3106b275 0x336b 0x330e57eb 0x330df3bd 0x330ad921 0x330ad3bf 0x330acd2d 0x33c98e13 0x310e7553 0x310e74f5 0x310e6343 0x310694dd 0x310693a5 0x330de457 0x330db743 0x2acd 0x2a28)
If I kept only the first 5 setTitle it will work, but if its more than 5 it will crash!
Please note that I'm creating the UITabBarController in IB not programatically.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试访问 tabController 上的 viewControllers 数组,然后直接编辑视图控制器上的 tabItem。
Try accessing the viewControllers array on the tabController instead and editing the tabItem on the View Controller directly.