首页 > 代码库 > UINavigationController 缺点之一

UINavigationController 缺点之一

在项目开发中遇到下面几个问题:

1. 有些viewcontroller是中间界面(或者叫做过渡界面)是不能返回的

2. 有时候,想更新一下已经push到navigationController中的viewController。

3. 前两个结合的情况。



stackOverflow中给过解决方法,也凑效,下面的代码是针对第三种需求的解决方案

        //获得视图栈
        NSMutableArray *navigationStack = [[NSMutableArray alloc] initWithArray:
                                           self.navigationController.viewControllers];
        //找到GroupListVC,并移除
        for (UIViewController *controller in navigationStack) {
            if ([controller isKindOfClass:[GroupListVC class]]) {
                vc = (GroupListVC*)controller;
		[navigationStack removeObject:vc];
		break; 
		} 
	} 
	//对视图栈进行重新赋值 
	self.navigationController.viewControllers = navigationStack;
	GroupListVC *vc = [[GroupListVC alloc]init];//新建GroupListVC
	vc.listtype = FGroupListFromAddressCreateGroup; 
	[self.navigationController pushViewController:vc animated:YES]; 

	//不让自己进入stack 
	navigationStack = [[NSMutableArray alloc] initWithArray: self.navigationController.viewControllers]; 
	for (UIViewController *controller in navigationStack) { 
		if ([controller isKindOfClass:[Select_GroupChatViewController class]]) { 
			[navigationStack removeObject:controller]; 
			break; 
			} 
		} 
	self.navigationController.viewControllers = navigationStack;

终究iOS SDK应该一个便捷得解决办法,比如enablePushNavigationController


UINavigationController 缺点之一