我改變標籤欄控制器有一些困難。基本上我有3個控制器的UITabBarController。第一次當應用程序啓動。我改變一個控制器是這樣的:UItabBar更改視圖控制器
NSMutableArray *muteArray = [[NSMutableArray alloc] init];
FirstPage *online;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
online =[[FirstPage alloc] initWithNibName:nil bundle:nil];
}else{
online =[[FirstPage alloc] initWithNibName:nil bundle:nil];
}
//adding all controllers of tab bar to array
[muteArray addObjectsFromArray:_navigationCotroller.viewControllers];
online.tabBarControllers = [muteArray copy];
//replacing object of login controller to after login controller
[muteArray replaceObjectAtIndex:1 withObject:online];
[online release];
//setting new controllers to tab bar
[_navigationCotroller setViewControllers:muteArray animated:YES];
[muteArray release];
然後在第一頁控制器我做了一些改變,然後按OK。現在我需要再次改變控制器,這樣做:
NSLog(@"Before change Tab Bar cotrollers = %@",self.tabBarController.viewControllers);
[self.tabBarController setViewControllers:_tabBarControllers animated:YES];
NSLog(@"After change Tab Bar cotrollers = %@",self.tabBarController.viewControllers);
[self.tabBarController.tabBarController setSelectedIndex:1];
_tabBarControllers是控制器時,應用程序啓動,我保存的陣列。
此代碼更改控制器,但是當我想打開更改的控制器與setSelectedIndex它不起作用。
任何想法?
和打印這樣的:
前更改標籤欄cotrollers = NULL 後更改標籤欄cotrollers = NULL
_navigationCotroller也是你的代碼中的錯字? –
_navigationCotroller是主要的UITabBarController – Streetboy
介意那裏缺少「N」字符;)_navigationCotroller - > _navigationCoNtroller –