UItabBar更改视图控制器 [英] UItabBar changing View Controllers

查看:88
本文介绍了UItabBar更改视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i have some difficulties changing tab bar controllers. Basically I have UITabBarController with 3 controllers. First time when app starts. I change one controller like this:

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];

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

Then in FirstPage controller i do some change and press OK. Now i need to change controllers again, doing this:

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是应用程序启动时保存的控制器数组。

_tabBarControllers is array of controllers which i saved when app started.

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

This code change controllers, but when i want to open changed controller with setSelectedIndex it don't work.

任何想法?

并打印出来:

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

Before change Tab Bar cotrollers = NULL After change Tab Bar cotrollers = NULL

推荐答案

首先我假设你的意思:

[self.tabBarController setSelectedIndex:1];

如果你的_tabBarControllers问题听起来不合适。

Failing that it sounds like the problem is with your _tabBarControllers.

以下输出是什么:

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

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

Does the following successfully remove the first tab with no problems?

NSMutableArray* newArray = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers];
[newArray removeObjectAtIndex:0]; 
[self.tabBarController setViewControllers:newArray animated:YES];

编辑2:

尝试更改:

[muteArray addObjectsFromArray:_navigationCotroller.viewControllers];
online.tabBarControllers = [muteArray copy];
[muteArray replaceObjectAtIndex:1 withObject:online];

to:

[muteArray addObjectsFromArray:self.tabBarController.viewControllers];
[muteArray replaceObjectAtIndex:1 withObject:online];
online.tabBarControllers = [muteArray copy];

说实话,我发现很难关注你的app结构和对象引用。

To be honest I'm finding it hard to follow your app structure and object references.

这篇关于UItabBar更改视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆