iOS8 UISplitViewController: How to switch to master view in compact width window? - ios8

My root view controller is an UISplitViewController, which has a UITableViewController as master view controller. On iPhone (compact width), it looks like a UINavigationController.
Tap a cell to show detail view controller
Tapping the trash button would delete the current note. My problem is how to go back to the master view after that? Since it's an UISplitViewController, it can't pop the current view controller as UINavigationController does.

I had a similar problem and finally found a solution. As I understand it, when in compact width, the detail navigation controller becomes a view controller of the master navigation controller. So all you have to do is:
Determine if only one view is present by checking the split view controller's collapsed property. If it isn't collapsed (e.g. on iPad), you're already showing the table view in addition to the detail view.
If it is collapsed (e.g. on iPhone) get a reference to the master navigation controller via the detail navigation controller and have it pop to its root view controller which, in this case the your table view controller.
This is the code I use in my detail view controller. In your case I think you just need to add this code to the button action in your detail view controller:
if splitViewController!.collapsed {
let detailNavController = parentViewController as UINavigationController!
let masterNavController = detailNavController.parentViewController as UINavigationController!
masterNavController.popToRootViewControllerAnimated(true)
}
Good luck!

Related

What happened to "Is initial view controller"checkbox?

I just added a second view controller to my project, but when I went to set is as the initial view controller, the very convenient checkbox was missing (the Title label is also missing). I embedded it into a navigation controller just to see what was up, and the checkbox was available for the nav controller. We used to be able to have a project with two view controllers, no nav controller, and be able to simply check the box to set which was the initial. Is this a bug or a deliberate move away from the checkbox in anything that's not a navigation controller?
View controller (no checkbox):
Navigation controller:
That Inspector's contents look a lot like you have selected the view controller's main view, not the view controller itself.

Table view cell segue to view controller not working (Swift)

I have a table view cell, which I am trying to connect to a view controller (table view is menu, titled equations) (view controller also has navigation controller and navigation bar, titled quadratics), however, when I control-click the table view cell and drag to the view controller and select "show", it works in the build, but it does not show a back button in the view controller, would there be any way to fix this (preferably with a story board and not programmatically).
Also, how would I make the animation from table view to view controller a right to left slide, and vice versa?
You do not need to have the second navigation controller in between your 2nd and 3rd view controller. Delete the navigation controller between your menu (table view controller) and equations view. And create a segue between them directly. This will add the equations view to the navigation stack and you will get the desired animation and back button automatically.

Swift back button with segue show not showing

So I tried everything with showing up the back button but it just won't work
This is how i arrange my View Controllers Used segue show from view controller to site view controller
And here is the site view controller that isn't showing back button
I even tried adding NavigationBar and a button with this function
self.navigationController.popToRootViewControllerAnimated(true)
Also failed
Update:
I tried this in both view controllers it's returning nil
in viewDidAppear and viewWillAppear
print(self.navigationController?.restorationIdentifier)
Once I got the same problem, when I was try to use view property of my UIViewController before it loaded properly. This caused problems with loading my navigation bar items. In fact, you should not touch view property until viewDidLoad method is called. Check, maybe it is your case, maybe you use view property in prepareForSegue method or in observers?

Create a segue to a different NavigationController

I have an app that has two navigation controllers. I'm trying to create the segue shown in the red arrow below: Pressing the "+" button should take you to a specific view controller of another NavigationController.
I've been able to successfully go to this view controller but it doesn't have any navigation properties (Pressing "Back" doesn't do anything).
How do I jump to a view controller in a different navigation controller but still retain navigation properties?
I will say you want to move from controller A to controller B for reference.
Each UINavigationController instance has a viewControllers array that stores the controllers in the navigation stack.
In your case, the first navigation controller has 2 view controllers in the navigation stack, the same thing for the second navigation controller.
If you press back in the view controller B, it should pop to one of the view controllers in the UINavigationController stack to which B belongs. Since controller A et B don't belong to the same UINavigationController, hence you cannot access the pop API to move back.
One way is to present controller B modally from controller A instead of pushing it.

Storyboards: A loop of Modal Segues?

I want to implement something using Storyboards, but I don't know the best way to accomplish it.
I don't want to use a Navigation Controller, since I don't want the navigation bar at the top.
I just want the ability to switch from one view controller to the next.
I have a Main Menu view controller, which will segue into other views, and those views might segue to other views... Now, lets say that the last view in the chain has a "Return To Menu" button: should I just segue from that button to the Menu view controller? Or should I somehow dismiss all of the previous view controllers?
I don't need iOS to hold a copy of the Main Menu view controller after the user taps out of it, but I can't seem to find a way to just load a new view controller and present it, instead of having a parent view display it "modally".
Would it cause a memory leak if I just create a loop of modal segues?
(for example: Main Menu --> VC1 --> VC2 --> Main Menu --> VC3 --> VC4 --> Main Menu...)
Any help will be much appreciated.
Thanks!
Each segue creates a new instance of the destination view controller, so having a segue back to the main menu is not a good idea.
You would be better off dismissing the presented view controller(s), but note that it is possible to use a navigation controller without showing the navigation bar - the navigation controller has a property, navigationBarHidden, which you can set to hide this.

Resources