0

我对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吗?因为我也尝试过。它不工作。

+0

你可以尝试在主线程上运行popviewcontroller方法吗? – Basheer

+0

remove let _ =,self.navigationController?.popToRootViewController(animated:true)是什么需要 –

+0

U只表示这个self.navigationController?.popViewController(animated:true)? – kishor0011

回答

1

检查要调用的如果是这种这种错误

let controller = SubmitRequestViewController.init(nibName: "SubmitRequestViewController", bundle: nil) 
    self.navigationController?.pushViewController(controller, animated: true) 
+0

你的意思是我在ViewWillAppear中写它? – kishor0011

+0

是的,我的意思是,或者当你介绍这个rootController时触发的任何函数 –

+0

其实我正在做的是我正在发射通知。我将关闭抽屉,然后我会发出通知并致电。 – kishor0011

1

我不能再出现这个问题你ViewWillapper

调用。

我想你必须发射两次推动动作。

  • viewDidLoadSubmitRequestViewController添加断点检查viewDidLoad被称为两次
  • 如果你开除它的故事板,再编程
  • 删除笔尖,再创检查,如果这是Xcode中
  • 的错误
  • 检查
+0

好的,我会尝试一次。谢谢 – kishor0011

相关问题