我想模仿ios中的联系人列表。当单击+按钮添加联系人时,会显示一个新的视图控制器,为您提供输入联系人姓名的文本字段以及用于保存该联系人的其他信息。点击完成按钮后,显示的下一个视图控制器似乎已嵌入导航控制器中,并带有一个按钮,可将您带回联系人列表。我已经尝试了在这里找到的代码,但它将3个视图推送到导航堆栈
//first attempt
var controllers = navigationController?.viewControllers
controllers?.append(secondVc)
controllers?.append(thirdVC)
navigationController?.setViewControllers(controllers!, animated: true)
//second attempt
let pushVC = UIViewController()
let backVC = UIViewController()
if let navigationController = navigationController {
navigationController.pushViewController(pushVC, animated: true)
let stackCount = navigationController.viewControllers.count
let addIndex = stackCount - 1
navigationController.viewControllers.insert(backVC, atIndex: addIndex)
}
我也尝试了其他看似狡猾的组合。这就是我想要的样子:documentation
答案 0 :(得分:3)
这应该有效:
navigationController.pushViewController(secondVc, animated:false)
navigationController.pushViewController(thirdVc, animated:true)
答案 1 :(得分:2)