0

我已使用以下代码从导航控制器(视图控制器)中删除我的登录页面,以便在返回时它不会再次进入视图(后退按钮)。

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
    NSMutableArray *VCs = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
    if([[VCs objectAtIndex:[VCs count] - 2] isKindOfClass:[loginViewController class]]&&(VCs.count>=4))
    {
        [VCs removeObjectAtIndex:[VCs count] - 2];
        [VCs removeObjectAtIndex:[VCs count] - 2];
        [self.navigationController setViewControllers: VCs];
    }
}

这适用于 iPhone。但是对于 iPad,因为我们使用的是 splitViewController,如果我们这样编码

NSMutableArray *VCs = [NSMutableArray arrayWithArray:self.splitViewController.viewControllers];

我们将得到的是一个导航控制器数组。是否有真正的逻辑可以让我们从 splitviewcontroller 中删除特定的 viewcontroller?

4

1 回答 1

2

正如您所说,您的拆分视图控制器将返回一个导航控制器数组(取决于项目设置)。一旦你参考了这些,你可以随心所欲地操纵它们。

UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *masterNavVC = (UINavigationController *)splitViewController.viewControllers.firstObject;
UINavigationController *detailNavVC = (UINavigationController *)splitViewController.viewControllers.lastObject;

//Now you have the master and detail navigation controllers, get your VC you need to manipulate
NSMutableArray *masterVCs = masterNavVC.viewControllers;
NSMutableArray *detailVCs = detailNavVC.viewControllers;

//Remove the ones you need to - this example is arbitrary. Put your logic here
if(masterVCs.count > 0 && [masterVCs[0] isKindOfClass:[LoginViewController class]])
{
     //Remove or add
}
于 2015-03-11T13:48:30.047 回答