I have an iPhone app and I'm trying to make it universal.
I added a split view controller and both its master and detail VCs are embedded in navigation controllers, so the navigation bar will show on both when they're visible at the same time, and I can add that displayModeButtonItem()
and all.
The problem is that, on the iPhone, when only one of the VCs is visible at a time, the extra navigation controller that the detail VC is embedded with will cause the back button to sort of blink on the show detail segue.
The difference is subtle, but it's really bugging me.
Here's how it goes without the extra navigation controller:
And here's how it goes with the extra navigation controller:
In the gifs it doesn't look as bad as in the actual iPhone, but you can see the difference. It's like with the extra navigation controller the back arrow shows up by itself, and then the "Reading" label catches up. Without the extra navigation controller, on the other hand, the back arrow and the "Reading" label show up at the same time (pay attention, you'll see it, haha).
To work around that I tried to change the segue so that then when tapping on a table view row in the master VC I'd go straight to the actual detail VC, bypassing its navigation controller. That seemed to work at first, but it led to other problems. For instance, if I were on the iPad and I pushed other VCs on top of the detail VC and then tapped another row on the master VC, the detail VC wouldn't pop back to its root VC, even when I explicitly told it to in didSelectRowAtIndexPath
.
So am I doing something wrong here, or is that just a UISplitViewController
quirk? Does anyone know how to fix or work around it?
Thanks!
Ok, I figured it out.
I had this in my detail VC's viewDidLoad
when the problem was happening:
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem()
self.navigationItem.leftItemsSupplementBackButton = true
}
And I noticed that the problem was caused by setting the leftBarButtonItem
. So I changed it to this, and now it works great:
override func viewDidLoad() {
super.viewDidLoad()
if self.splitViewController?.collapsed == false {
self.navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem()
self.navigationItem.leftItemsSupplementBackButton = true
}
}