I have read the guidelines for contributing and I understand:
viewWillAppear on menu's table view is called properly only on first appearance. After that, it is not called before menu appears but only after it disappears.
The Example project is based on storyboards, but this issue appears when I setup menu in code. Here is very basic project with menu setup code taken from README: https://github.com/paiv/sidemenuappear/blob/master/sidemenuappear/ViewController.swift
2.3.3:
viewWillAppearviewDidAppearviewWillAppearviewDidAppearInstead, viewWillAppear should happen just before menu appears. App depends on this event to update menu data before user sees it.
In 2.3.2: viewWillAppear and viewDidAppear were invoked at appropriate moments
In UISideMenuNavigationController
// Hack: force selection to get cleared on UITableViewControllers when reappearing using custom transitions
visibleViewController?.viewWillAppear(false)
I suppose this could be replaced by directly removing selection from rows, like
if let tableView = (visibleViewController as? UITableViewController)?.tableView {
if let indexPath = tableView.indexPathForSelectedRow {
tableView.deselectRow(at: indexPath, animated: false)
}
}
+1 have the same behaviour. viewWillAppear is called when the menu is dismissed...
This hack has actually been in the library for quite some time, although it used to be located in viewWillDisappear before. @paiv, have you tested the code snippet yourself? The reason I called viewWillAppear is because it depends on whether or not the selection is _supposed_ to be cleared depending on the clearsSelectionOnViewWillAppear property of the view controller.
@jonkykong which snippet do you refer to? Yes, I've tested everything I posted.
In the simple project I linked you can clearly see the change in behavior between 2.3.2 and 2.3.3.
By forcing viewWillAppear at disappear time you actually breaking UIViewController API. Apps do not expect this.
Better, you should have in SideMenu API your own flag telling whether to clear selection on disappear.
@paiv I don't think a separate flag is the right idea as clearsSelectionOnViewWillAppear already exists and creating a new one would be redundant.
Prior to 2.3.3, I had this same call to viewWillAppear inside of viewWillDisappear so this hack has been in place for some time with no complaints. It doesn't break the API as everything continues to keep working, however if you have overridden these methods you may not be expecting the result.
At any rate, a solution that is based on clearsSelectionOnViewWillAppear and deselects the content on close is the right solution. It's going to be a while before I can get to fixing this as I have a lot on my plate at the moment.
So is it "safe" to just uncomment the whole viewDidDisappear?
It also broke my app, as now the viewController, which is being dismissed (the sidemenu) now receives a viewWillAppear, which is definitely wrong, because the viewController is being dismissed and so it just seems wrong to send it a viewWillAppear (which in my case causes the underlying view to be covered) (I do not know much about this app, it has been made by another developer and now I am only here to make some quick fixes.) It seems at least in case of this app, just uncommenting the whole viewDidDisappear fixes my problem.
@a7ex yes, it should be safe. The only purpose of it is to deselect the rows of the table view the next time the menu is revealed since the method wasn't getting called automatically by the custom transition APIs.
Hi,
I have the same problem. Did you find any solution?
I removed the hack and it works fine. I don't use UITableViewController to represent menu - just UIViewController.
Probably, you need to add something like this:
if visibleViewController is UITableViewController {
visibleViewController?.viewWillAppear(false)
}
In my case just uncommenting the whole viewDidDisappear fixed my issue and I haven't experienced side issues.
Have the same story.
Delete viewDidDisapper as @a7ex propose and everything start to work like a charm
depends on whether the word "charm" can be applied to a "Hamburger Menu" on iOS in the first place ;-)
I for one hate "Hamburger Menu" and fortunately clients started to understand why some time ago. But that's of course OT and by no means I am diminuishing the good work, which has been done for the SideMenu POD.
This is fixed in 3.0.1.
Most helpful comment
In UISideMenuNavigationController
I suppose this could be replaced by directly removing selection from rows, like