UISplitViewController master view calling performSegueWithIdentifier on detail view - ios

I am calling performSegueWithIdentifier on a detail view controller from my master UIViewController.
For some reason, the segue is not performing. It is an unwind segue. I have the IBAction in place in the view controller I am segueing too. I have the unwind segue setup to point to that action. The master view controller has the correct reference to the detail view controller. I change a color on the detail just to make sure I am referencing the right thing. Also, if I type the name of the identifier wrong it crashes. If I type it correctly, it runs just fine as if it knows it is there.
But it just won't segue!
What could be wrong?

I discovered that the UISplitViewController needs UINavigationControllers as its master and detail view for an unwind segue to work. Even though you can perform a push segue without a UINavigationController it seems a UINavigationController is necessary for an unwind segue.

Related

UINavigation issue in App

i have multiple storyboard in my storyboard. I have embedded the firstVC with navigationcontroller and remaining attached to the firstvc through segues. The remaining VC's are not embedded in navigationcontroller. Now when i click the button to open the next VC without navigation controller. It opens it twice. When i disconnect the segue it does not open the VC. I'm confused that why this is happening so. This is how my UI Looks,
This is how i perform the segue,
self.performSegue(withIdentifier: "GoToNextVC", sender: self)
View Controllers operate on a stack hierarchy. By embedding your first view controller in a UINavigationController and setting that as the Initial View Controller, you're making it the root view controller for the whole stack. The issue you are experiencing is occurring because you are segueing to view controllers without the root view controller's knowledge every time you call performSegue(withIdentifier:sender:). This causes the stack to be out of order and disjointed, preventing you from returning to the previous view controller(s) when calling dismiss(animated:completion:).
Instead of segues, try pushing each view controller to the stack with:
navigationController?.pushViewController(VIEW_CONTROLLER, animated: true)
To use this:
Remove any segues in Interface Builder, they are no longer needed.
Replace VIEW_CONTROLLER with the view controller you want to push.

Segue from one view controller embedded within UINavigationController to another UINavigationController

I have a UINavigationController as my root controller, but then I segue from one view controller to another UINavigationController.
But when segueing from one view controller which is embedded within a UINavigationController to another UINavigationController the push segue comes from the bottom, presuming it is segueing as a popover. I tried using a show detail segue but still not luck.
Why is this occurring and how can I segue from one to the other using a push/replace segue ?
PS: Is this happening because the UINavigationControllers conflict and overrides the segue as a popover ? The reason I am using two separate navigation controllers is because the style from the previous view overrides the style of the detail view, i posted a separate question about that Cannot change style of UINavigationBar when using scrollViewDidScroll on separate View Controller
Push segue occurs only within one navigation controller. It's how it implements 'show' type segue. Making 'show' segue from navigation controller to another navigation controller is not what Xcode drawing tool considered as 'pushing'. It interprets it as popover by default.

Unwind segue in multiple storyboards environment

My app has more than two storyboards. In storyboard A, it has navigation view controller, root view controller and several view controllers.
It also has an unwind segue, like returnToTopScreen.
Storyboard B has several view controllers. At execution, all VC in B is on the navigation stack.
My question is,
Can unwind segue work for inter storyboards unwinding?
According to my trial, Xcode6.2 allows a UIbutton in VC of storyboard B to connect with an unwind segue in storyboard A. But it does not work.
Yes, you can unwind between storyboards as long as you got to the controller in the second storyboard by pushing or presenting from one of the controllers in the sequence that leads back to the one you want to unwind to. I tested this in a setup where the main storyboard had a navigation controller with its root view controller, and one other controller that was pushed to from the root. In that controller, I instantiated the controller in the second storyboard, and either pushed or presented it. An unwind from that controller in the second storyboard successfully went back to the root of the navigation controller.

iOS Storyboard Presenting Segues "relationship, embed, push, modal, custom" types

I have a basic idea what push and modal segues do. Push is used for Navigation Controller segues and Modal is the default one I've been using so far for a basic segue into another View Controller. I assume "modal" means nothing else can be going on/interrupting the segue?
Custom segues I guess are the most flexible/customizable/animatable.
I have no idea what "relationship" and "embed" segues do. Please let me know!
Thank you.
A "relationship" segue is the segue between a container view controller and its child or children -- so, the initial controller of a navigation controller, the view controllers in the tabs of a tab bar controller, and the master and detail controllers of a split view controller.
An "embed" segue is the segue between a container view and the controller that's embedded in that container view that you get automatically when you add a container view to a controller's view.
Both of these segues are executed as soon as the parent controller gets instantiated. You do not call them, but you can implement prepareForSegue, and pass information to the destination view controller.

Adding viewcontrollers to navcontroller with storyboard

I have a basic storyboard setup where I load my NavViewController, which then points to initial view controller. I then have several additional view controllers all daisy chained together via segues in a linear fashion. When I initially launch my application i run the following in my NavControllerViewController.m
(void)viewDidLoad
{
[super viewDidLoad];
NSArray * controllerArray = [self viewControllers];
NSLog(#"view controllers: %#", controllerArray);
}
The log only shows the very first root view controller (the one directly 'connected' to the nav controller). All over view controllers are missing from the stack. I was under the impression that if a view controller was on my storyboard that it would automatically be added to the nav controller?
If this is not correct, would a good alternative be to instantiate each VC, from the calling VC? For example, if I wanted to transition from VC1 to the VC2, would I put the following code in VC1:
UIViewController *vc2 = [self.storyboard instantiateViewControllerWithIdentifier:#"vc2"];
[self pushViewController:vc2 animated:YES];
Or possibly:
[self performSegueWithIdentifier:#"vc2Segue" sender:self];
They are all able to be reached by segues, but they are not instantiated or pushed onto the stack until you segue to them.
You could use the self perform segue tactic, or the push view controller, or, alternatively, if it is in response to a single button click, just control drag from that button to the next view controller and Xcode does all the rest of the work for you.
If I understand your question correctly, you have a storyboard setup looking similar to the below screen shot.When an application loads this storyboard it will definitely have only one view controller in the navigation controller stack and that will be the root view controller.
Because other view controllers are still not pushed into the navigation controller stack.
In the Viewcontroller-1, you could see a button some Action, I have created a push segue from that button to the Viewcontroller-2.Once you tap that button, second view controller will be pushed to the navigation controller stack.
If you print the viewcontrollers count now, you should get the count as 2.
Repeat the same in the View Controller-2, now you can see the count bumps to 3. Because now we have three view controllers pushed into the navigation controller stack.
Press the back button to pop the view controllers and could see the view controllers count coming down, that's because view controllers are now being removed from navigation controller stack.
As AdamG stated, the UIViewControllers will not be pushed on to the stack until you segue to them.
To set a segue, select a UIViewController and control+drag the connection to the target UIViewController. Under the Attributes Inspector tab set the Storyboard Segue Identifier.
To segue to a UIViewController use the method performSegueWithIdentifier:. Before performSegueWithIdentifier: is called prepareForSegue:sender: will be called. This is where you can pass any values that the next UIViewController needs. To check which segue is being called use the segue.identifier property in prepareForSegue:sender:. After that, you can access the destinationViewController property.
If you need to manually instantiate a UIViewController use instantiateViewControllerWithIdentifer:. The identifier can be set under the Identity Inspector tab in the storyboard.

Resources