- (voID)tabbarController:(UITabbarController *)tabbarController dIDSelectVIEwController:(UIVIEwController *)vIEwController{ if ([self.tabbarController.selectedVIEwController.Title isEqualToString:@"All"]) { //do something }}解决方法 无论何时在UITabbarController中选择视图控制器,都会调用您提到的方法,最重要的是,当前显示的视图控制器将作为参数传递给您;然后,您可以使用以下代码查找控制器的类和标题,包括“更多”控制器:
- (voID)tabbarController:(UITabbarController *)tabbarController dIDSelectVIEwController:(UIVIEwController *)vIEwController{ NSLog(@"controller class: %@",NsstringFromClass([vIEwController class])); NSLog(@"controller Title: %@",vIEwController.Title);}
在快速测试中,只需在Xcode中添加几个控制器,这就是您在控制台中获得的:
2011-03-28 09:13:21.795 TabTest[39015:207] controller class: UIVIEwController2011-03-28 09:13:21.797 TabTest[39015:207] controller Title: (null)2011-03-28 09:13:23.922 TabTest[39015:207] controller class: UItableVIEwController2011-03-28 09:13:23.925 TabTest[39015:207] controller Title: (null)2011-03-28 09:13:24.505 TabTest[39015:207] controller class: UItableVIEwController2011-03-28 09:13:24.506 TabTest[39015:207] controller Title: (null)2011-03-28 09:13:24.945 TabTest[39015:207] controller class: UIMoreNavigationController2011-03-28 09:13:24.945 TabTest[39015:207] controller Title: More
另一方面,当您在“更多”列表中选择一个控制器时,您将不会在UITabbarControllerDelegate方法中得到通知(很奇怪,恕我直言).为了帮助您在该列表中选择控制器时收到通知,您可以执行以下 *** 作:
- (voID)tabbarController:(UITabbarController *)tabbarController dIDSelectVIEwController:(UIVIEwController *)vIEwController{ NSLog(@"controller class: %@",vIEwController.Title); if (vIEwController == tabbarController.moreNavigationController) { tabbarController.moreNavigationController.delegate = self; }}- (voID)navigationController:(UINavigationController *)navigationController dIDShowVIEwController:(UIVIEwController *)vIEwController animated:(BOol)animated{ if (navigationController == self.tabbarController.moreNavigationController) { NSLog(@"more controller class: %@",NsstringFromClass([vIEwController class])); NSLog(@"more controller Title: %@",vIEwController.Title); }}
当然,您的类还应该实现UINavigationControllerDelegate协议.
这是样本运行的结果,使用上面的代码并在UITabbar和“more”列表中点击几次:
2011-03-28 09:27:42.496 TabTest[39113:207] controller class: UIVIEwController2011-03-28 09:27:42.498 TabTest[39113:207] controller Title: (null)2011-03-28 09:27:44.306 TabTest[39113:207] controller class: UIMoreNavigationController2011-03-28 09:27:44.307 TabTest[39113:207] controller Title: More2011-03-28 09:27:44.310 TabTest[39113:207] more controller class: UIMoreListController2011-03-28 09:27:44.311 TabTest[39113:207] more controller Title: More2011-03-28 09:27:45.632 TabTest[39113:207] more controller class: SecondVIEwController2011-03-28 09:27:45.634 TabTest[39113:207] more controller Title: (null)2011-03-28 09:27:47.156 TabTest[39113:207] more controller class: UIMoreListController2011-03-28 09:27:47.156 TabTest[39113:207] more controller Title: More2011-03-28 09:27:48.581 TabTest[39113:207] controller class: UItableVIEwController2011-03-28 09:27:48.582 TabTest[39113:207] controller Title: (null)
希望这可以帮助!
总结以上是内存溢出为你收集整理的iphone – 如何在更多部分获得UITabBarItem的标题?全部内容,希望文章能够帮你解决iphone – 如何在更多部分获得UITabBarItem的标题?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)