I have been implementing SideMenu in my iOS app (mailbox). The SideMenu is used to choose the current folder. I created a SideMenu navigation controller and attached a UITableViewController
as the root 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. When I tried to call the load function directly, Xcode said that my tableView
was nil (it wasn't when it first loaded).
Here is my code for didSelectRowAtIndexPath
in the SideMenu table:
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:
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:
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. 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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.