iPad(UISplitViewController)iosxcode中如何控制后退按钮导航
How to control the back button navigation in iPad (UISplitViewController)ios xcode
我已使用以下代码从导航控制器 (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];
我们将得到一个导航控制器数组。是否存在我们可以从拆分 viewcontroller 中删除特定 viewcontroller 的真正逻辑?
如您所说,您的拆分视图控制器将 return 一组导航控制器(取决于项目设置)。一旦你有了对它们的引用,你就可以随心所欲地操纵它们。
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
}
我已使用以下代码从导航控制器 (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];
我们将得到一个导航控制器数组。是否存在我们可以从拆分 viewcontroller 中删除特定 viewcontroller 的真正逻辑?
如您所说,您的拆分视图控制器将 return 一组导航控制器(取决于项目设置)。一旦你有了对它们的引用,你就可以随心所欲地操纵它们。
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
}