UItabBar更改视图控制器

Str*_*boy 6 iphone objective-c uitabbarcontroller uitabbar ios

我在更改标签栏控制器时遇到一些困难.基本上我有UITabBarController与3个控制器.应用程序启动时的第一次 我改变了这样一个控制器:

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];
Run Code Online (Sandbox Code Playgroud)

然后在FirstPage控制器中我做了一些更改,然后按确定.现在我需要再次更改控制器,这样做:

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];
Run Code Online (Sandbox Code Playgroud)

_tabBarControllers是应用程序启动时保存的控制器数组.

此代码更改控制器,但是当我想用setSelectedIndex打开更改的控制器时,它不起作用.

有任何想法吗 ?

打印这个:

更改之前Tab Bar cotrollers = NULL更改后Tab Bar cotrollers = NULL

ade*_*der 11

首先我假设你的意思是:

[self.tabBarController setSelectedIndex:1];
Run Code Online (Sandbox Code Playgroud)

如果你的_tabBarControllers出现问题,那就不是问题了.

以下输出是什么:

NSLog(@" _tabBarControllers count = %d", [_tabBarControllers count]);
NSArray* newArray = [NSArray arrayWithArray:self.tabBarController.viewControllers];
NSLog(@" newArray count = %d", [newArray count]);
Run Code Online (Sandbox Code Playgroud)

编辑:以下是否成功删除第一个选项卡没有问题?

NSMutableArray* newArray = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers];
[newArray removeObjectAtIndex:0]; 
[self.tabBarController setViewControllers:newArray animated:YES];
Run Code Online (Sandbox Code Playgroud)

编辑2:

尝试改变:

[muteArray addObjectsFromArray:_navigationCotroller.viewControllers];
online.tabBarControllers = [muteArray copy];
[muteArray replaceObjectAtIndex:1 withObject:online];
Run Code Online (Sandbox Code Playgroud)

至:

[muteArray addObjectsFromArray:self.tabBarController.viewControllers];
[muteArray replaceObjectAtIndex:1 withObject:online];
online.tabBarControllers = [muteArray copy];
Run Code Online (Sandbox Code Playgroud)

说实话,我发现很难遵循你的应用程序结构和对象引用.