简体   繁体   English

当视图控制器(SideMenu)出现时,视图并未显示未调用

[英]View did appear not called when view controller (SideMenu)

I have been implementing SideMenu in my iOS app (mailbox). 我一直在我的iOS应用程序(邮箱)中实现SideMenu The SideMenu is used to choose the current folder. SideMenu用于选择当前文件夹。 I created a SideMenu navigation controller and attached a UITableViewController as the root vc. 我创建了SideMenu导航控制器,并将UITableViewController附加为根vc。

It works perfectly fine, up until the point where I click on one of the cells, which dismisses the side menu and should load the mail in the original view controller. 直到我单击其中一个单元格为止,它都可以正常工作,这将关闭侧面菜单,并应将邮件加载到原始视图控制器中。 However, the original view controller's viewDidAppear method is not called. 但是,未调用原始视图控制器的viewDidAppear方法。 When I tried to call the load function directly, Xcode said that my tableView was nil (it wasn't when it first loaded). 当我尝试直接调用load函数时,Xcode表示我的tableView为nil(不是第一次加载时)。

Here is my code for didSelectRowAtIndexPath in the SideMenu table: 这是我在SideMenu表中的didSelectRowAtIndexPath代码:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    currentFolder = folders[indexPath.row].path
    tableView.deselectRow(at: indexPath, animated: true)
    self.dismiss(animated: true) {
        let vc = self.storyboard?.instantiateViewController(withIdentifier: "mail") as! MailViewController
        vc.loadMail()
    }

}

Here is the loadMail function in the original vc: 这是原始vc中的loadMail函数:

func loadMail(showsSpinner: Bool = true) {
    ...
    if let messages = fetchedMessages as? [MCOIMAPMessage] {
        self.mailsInFolder = messages
        SwiftSpinner.hide()
        self.refresher.endRefreshing()
        self.table.reloadData()
    }

}

Also, here is viewDidAppear in the original vc: 另外,这是原始vc中的viewDidAppear

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    print("viewDidAppear")
    let from = self.navigationController?.transitionCoordinator?.viewController(forKey: .from)
    if from is MessageViewController {
        print("from is message controller")//should not load
        return
    }
    self.loadMail()

}

Here, viewDidAppear is not called, and the mail doesn't load. 在这里,未调用viewDidAppear ,并且不会加载邮件。 What can I do to fix this? 我该怎么做才能解决此问题? Thanks! 谢谢!

I had been working with SideMenu for a while, and I suggest you to use as mainViewController a UINavigationController and then when select one cell of your tableView in the rightViewController 我已经使用SideMenu了一段时间,建议您使用UINavigationController作为mainViewController ,然后在mainViewController选择tableView的一个单元格

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    currentFolder = folders[indexPath.row].path
    tableView.deselectRow(at: indexPath, animated: true)
    if let vc = self.storyboard?.instantiateViewController(withIdentifier: "mail") as! MailViewController
    {
       mainNavController.setViewControllers([vc], animated: false)
    }
    homeSlide.slideMenuController()?.closeLeft()
}

I hope this helps you, best regards 希望这对您有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM