【发布时间】:2017-08-24 06:09:16
【问题描述】:
我对@987654321@ 堆栈有点困惑。
我正在通过我的rootViewController("ViewController") 显示我的UIViewController("SubmitRequestViewController")。
下面是我的代码:
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 不断增加。
我正在尝试弹出到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)
}
我正在做。我不知道我也必须删除观察者吗?因为我也试过了。它不工作。
【问题讨论】:
-
你可以尝试在主线程上运行popviewcontroller方法吗?
-
remove let _ = , self.navigationController?.popToRootViewController(animated: true) 是需要的
-
你的意思只是这个 self.navigationController?.popViewController(animated: true) ?
-
我试过@Basheer。但同样的问题。 DispatchQueue.main.async { self.navigationController?.popViewController(animated: true) }
-
也许你可以在 SubmitRequestViewController 中检查 deinit。
标签: ios swift uinavigationcontroller navigation pushviewcontroller