我使用以下代码从navigationcontroller(viewcontrollers)中删除我的登录页面,以便在返回时(后退按钮)不会再次进入视图。
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];
我们将获得的是一组navigationControllers。我们是否有一个真正的逻辑可以从splitviewcontroller中删除特定的viewcontroller?
答案 0 :(得分: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
}