UITabBarController 的 setTitle 在 iOS 5 中超过 5 个项目时崩溃?

发布于 2024-12-10 05:59:53 字数 1476 浏览 0 评论 0原文

在将我的 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 技术交流群。

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

发布评论

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

评论(1

时光匆匆的小流年 2024-12-17 05:59:53

尝试访问 tabController 上的 viewControllers 数组,然后直接编辑视图控制器上的 tabItem。

[[tabController.viewControllers objectAtIndex:0].tabBarItem setTitle:@"Tab1"];

Try accessing the viewControllers array on the tabController instead and editing the tabItem on the View Controller directly.

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