我对UINavigationController
堆栈有点困惑。 我从我的rootViewController("ViewController")
中显示我的UIViewController("SubmitRequestViewController")
。ViewController从我的rootViewController多次调用
下面是我的代码:
let controller = SubmitRequestViewController.init(nibName: "SubmitRequestViewController", bundle: nil)
self.navigationController?.pushViewController(controller, animated: true)
现在我只是想从SubmitRequestViewController
回来我rootViewController
。
//Home Button
@objc fileprivate func backHome() {
let _ = self.navigationController?.popToRootViewController(animated: true)
}
//Back Button
@objc fileprivate func backButton() {
let _ = self.navigationController?.popViewController(animated: true)
}
如果我再次去我的“SubmitRequestViewController
”它获得两次电话。
所以这是持续的。如果我将重复上述步骤,它会多次呼叫。
现在我得到的是: -
navigationController.viewControllers.count
是越来越continuesly增加。
我想弹出到navigationController
但仍然存在。
我想这也: -
self.navigationController?.dismiss(animated: true, completion: nil)
其实我开火,我DrawerViewController类的通知: -
//Submit Request
else if itemArray[indexPath.row].contains("SUBMIT REQUEST") == true {
tableView.deselectRow(at: indexPath, animated: false)
self.dismiss(animated: true, completion: nil)
NotificationCenter.default.post(name: Notification.Name(rawValue : AssessNowKyes.submitRequest), object: nil)
}.
我打电话在我ViewControllerClass: -
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(submitRequestClicked), name: Notification.Name(rawValue : AssessNowKyes.submitRequest), object: nil)
}
//Submit Request Clicked
@objc fileprivate func submitRequestClicked() {
let controller = SubmitRequestViewController.init(nibName: "SubmitRequestViewController", bundle: nil)
self.navigationController?.pushViewController(controller, animated: true)
}
我正在这样做。我不知道我必须删除Observer吗?因为我也尝试过。它不工作。
你可以尝试在主线程上运行popviewcontroller方法吗? – Basheer
remove let _ =,self.navigationController?.popToRootViewController(animated:true)是什么需要 –
U只表示这个self.navigationController?.popViewController(animated:true)? – kishor0011