gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 21:49:05 25 4
gpt4 key购买 nike

我使用以下代码从导航 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com