ios - 如何在 iPad (UISplitViewController) ios xcode 中控制后退按钮导航

标签 ios objective-c ipad back uisplitview

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

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

我们将得到的是一组导航 Controller 。是否存在我们可以从 splitviewcontroller 中删除特定 viewcontroller 的真正逻辑?

最佳答案

如您所说,您的 Split View Controller 将返回一个导航 Controller 数组(取决于项目设置)。一旦您获得了对它们的引用,您就可以随心所欲地操纵它们。

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
}

关于ios - 如何在 iPad (UISplitViewController) ios xcode 中控制后退按钮导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28987904/

相关文章:

objective-c - 当单元格包含 UITextView 时,不会触发 UITableView willDisplayCell

ios - 如何在为多个应用程序使用 CMS 和脚本的 Xcode 中集成 crashlytics

ios - 以编程方式打开 Storyboard 中的特定页面

iphone - 我的 NSUserDefaults 加载操作有什么问题吗?

ios - UIGraphicsBeginPDFContextToData 创建 Acrobat 无法读取的 PDF

ios - 对包含多个对象类的 NSArray 进行排序

iphone - 使用 Interface Builder 在屏幕外创建 UIButton

iphone - 如何在核心文本中呈现不同的段落样式?

ios - 仅更改部分 UIView 的颜色

iphone - 我应该在哪里存储图像,以便我可以使用 iTunes 文件共享它们?