gpt4 book ai didi

ios - 从导航堆栈中删除 ViewController

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:06:45 25 4
gpt4 key购买 nike

我用代码来做:

NSArray *viewControllersFromStack = [self.navigationController viewControllers];
NSMutableArray *viewControllersFromStackMutable = [NSMutableArray arrayWithArray:viewControllersFromStack];
NSMutableArray *viewControllersToRemove = [[NSMutableArray alloc]init];

for (UIViewController *currentVC in viewControllersFromStack)
{
if ([currentVC isKindOfClass:[TalksViewController class]])
{
[viewControllersToRemove addObject:currentVC];
if (viewControllersToRemove.count == 2)
{
UIViewController *oneVCtoRemove = [viewControllersToRemove objectAtIndex:0];
[viewControllersFromStackMutable removeObject:oneVCtoRemove];
[self.navigationController setViewControllers:viewControllersFromStackMutable];

}
}
}

问题是我在导航项中引用了已删除的 VC。如何解决?

最佳答案

当你想从导航栈中移除一个 View 时,你可以简单地在导航栏上调用这个方法来从栈中弹出 View :

[self.navigationController popViewControllerAnimated:YES];

弹出一个外部 View 使用

for(UIViewController *currentVC in viewControllersFromStack)
{
if([currentVC isKindOfClass:[TalksViewController class]])
{
[currentVC.navigationController popViewControllerAnimated:YES];
}
}

关于ios - 从导航堆栈中删除 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22649524/

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