按照代码更改选项卡名称,然后选择索引2.
[(UITabBarItem*)[self.rootController.tabBar.items objectAtIndex:0] setTitle:@"User"];
self.rootController.selectedIndex = 2;
然而,它适用于例如app didFinishLaunching方法但在调用时无法正常工作。
触摸内部按钮触发renameTabs:
- (IBAction) renameTabs: (id)sender
{
CompanyAppDelegate *theInstance = [[CompanyAppDelegate alloc] init];
[theInstance rename];
}
并在控制器中:
- (void) rename
{
[(UITabBarItem*)[self.rootController.tabBar.items objectAtIndex:0] setTitle:@"User"];
self.rootController.selectedIndex = 2;
}
重命名函数被触发并在.h中定义。没有错误但没有任何改变!有什么不对的吗??谢谢
答案 0 :(得分:3)
您不应该创建新的CompanyAppDelegate
。尝试在sharedAppDelegate
中实施方法CompanyAppDelegate.m
:
+ (CompanyAppDelegate *)sharedAppDelegate
{
return (CompanyAppDelegate *) [UIApplication sharedApplication].delegate;
}
不要忘记在CompanyAppDelegate.h
中声明它。
用这个替换renameTabs
:
- (IBAction) renameTabs: (id)sender
{
CompanyAppDelegate *theInstance = [CompanyAppDelegate sharedAppDelegate];
[theInstance rename];
}
答案 1 :(得分:1)
- (IBAction) renameTabs: (id)sender
{
CompanyAppDelegate *theInstance = (CompanyAppDelegate *) [UIApplication sharedApplication].delegate;
[theInstance rename];
}
- (void) rename
{
[(UITabBarItem*)[self.rootController.tabBar.items objectAtIndex:0] setTitle:@"User"];
self.rootController.selectedIndex = 2;
}
答案 2 :(得分:0)