我正在考虑更改标签栏上的图形,例如
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
UITabBarItem *tabBarItem4 = [tabBar.items objectAtIndex:3];
tabBarItem1.title = @"Home";
tabBarItem2.title = @"Maps";
tabBarItem3.title = @"My Plan";
tabBarItem4.title = @"Settings";
我这里的问题是我的 tabbarcontroller 不是我的 Root View ,所以我如何引用 tabbarcontroller 来更改选项卡图像?
我正在遵循这篇文章 ( Can I have more than 1 UITabBarController? ) 的建议,该建议指的是拥有一个链接到一个或多个 tabbarcontroller 的 tableview。
所以我的 Root View 不是标签栏,但标签栏 View 是在从前一个屏幕加载后加载的。
我有这一切工作,初始屏幕,然后是标签栏,一切正常,我只需要更改标签栏上的图形,但我无法做到这一点,因为所有关于更改标签的教程条形图使用 app delegate 并将 tabbarcontroller 称为 Root View 。
非常感谢对此的任何帮助!
最佳答案
选项卡栏项目属于每个选项卡中的各个内容 View Controller ,因此与其尝试引用选项卡栏 Controller ,不如更改这些 Controller 中的选项卡项目属性。如果您希望这些更改在标签栏 Controller 出现在屏幕上时立即可见,您需要将这些自定义设置放入它们的 awakeFromNib 或 initWithCoder 方法(对于在 IB 中设置的 Controller )。
关于ios - 当标签栏不是 Root View 时更改标签栏图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16532132/