3 回答
TA贡献1831条经验 获得超10个赞
使用此代码并享受:
NSMutableArray *navigationArray = [[NSMutableArray alloc] initWithArray: self.navigationController.viewControllers];
// [navigationArray removeAllObjects]; // This is just for remove all view controller from navigation stack.
[navigationArray removeObjectAtIndex: 2]; // You can pass your index here
self.navigationController.viewControllers = navigationArray;
[navigationArray release];
希望这会帮助你。
编辑:Swift代码
guard let navigationController = self.navigationController else { return }
var navigationArray = navigationController.viewControllers // To get all UIViewController stack as Array
navigationArray.remove(at: navigationArray.count - 2) // To remove previous UIViewController
self.navigationController?.viewControllers = navigationArray
TA贡献1802条经验 获得超5个赞
您可以首先获取数组中的所有视图控制器,然后在检查了相应的视图控制器类之后,可以删除所需的视图控制器。
这是一小段代码:
NSArray* tempVCA = [self.navigationController viewControllers];
for(UIViewController *tempVC in tempVCA)
{
if([tempVC isKindOfClass:[urViewControllerClass class]])
{
[tempVC removeFromParentViewController];
}
}
我认为这会使您的工作更轻松。
TA贡献1815条经验 获得超6个赞
斯威夫特3&4/5
self.navigationController!.viewControllers.removeAll()
self.navigationController?.viewControllers.remove(at: "insert here a number")
斯威夫特2.1
移除所有:
self.navigationController!.viewControllers.removeAll()
从索引处删除
self.navigationController?.viewControllers.removeAtIndex("insert here a number")
还有很多其他可能的动作,例如removeFirst,range等。
- 3 回答
- 0 关注
- 702 浏览
添加回答
举报