How to segue to same controller from different view? - iphone

I have a tab view controller with a few tabs. One tab leads to the "players" view through a navigation controller. A second tab leads to a "settings" view. The settings view has a button to select a "default" player and so it tries to segue to the players view through a separate navigation controller.
Diagram:
Players Tab -> Navigation Controller "A" -> Players View Controller
Settings Tab -> Navigation Controller "B" (w/named segue) -> Players View Controller
The Players tab view does not have a "named" segue as it has a relationship to the tab controller. The settings tab navigation controller has a named segue.
However, now when I select the "players" tab the view is empty! The navigation bar at the top is there with the tabs but that's it. As a test, I removed the relationship from Nav "B" to Players View and now the Players tab is working once again.
I am missing a fundamental issue here but I don't know what.
Any ideas whatsoever is appreciated.

I found a similar question with the answer I needed.
How to create a UIViewController layout in storyboard and then use it in code?
Here is the relevant code:
UIViewController *viewController = [[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:NULL] instantiateViewControllerWithIdentifier:#"ResultsController"];
[self presentModalViewController:viewController animated:NO];
I'm new to storyboards and so I was not aware that this method exists. This method solves the problem I described above. I was initially trying to segue through a navigation controller to a view that already had an established segue. With the solution here I can simply instantiate an existing view using an identifier.
I still think there should be a way to try another segue so that "perform segue" can be used. However, I am moving forward once again.

Related

Tabbar not showing after a segue?

I don't know what I'm doing wrong, but my UITabBar is not showing after a segue. Basically, the hierarchy goes like:
Tabbar > Navigation Controller > View Controller > Navigation Controller > View Controller
I tried removing the second UINavigationController in order to make that transition, the first (blue) UIViewController has a slide up menu (just a basic UIView with buttons, that's Y offset is off the screen, with basic animation) and when a button is clicked, it leads to the appropriate UIViewController. Once the View controller is presented, you no longer see the UITabBar. Basically, the View Controller tops it. I tried changing the segue from modally presented to push, but it doesn't change it. I don't know what I'm doing wrong.
Here's a screenshot of the UIStoryboard to illustrate that better. PS: The UITabBar is not visible on this UIStoryboard, but it's shown in the simulator. I can guarantee that.
UPDATE: Full screen of the storyboard added
Set your hierarchy like:-- Navigation > Tabbar > Navigation Controller > View Controller
When u try to push view controller from tab u set tabbar as navigation and most important thing is set your root view hierarchy.
set your break point where view controller is present and then in debug area "po(navigation cotroller)" it's may be nil.
I,it will help you.
Heirarchy of viewController:- Navigation1 > ViewController1 > Navigation2 > ViewController2.(By the this is not good way to handle this type of hierarchy)
when I push from ViewController1 to ViewController2 it will be present because of now set Navigation2 means ViewController2 set as root view Controller.
But I want to push ViewController1 to ViewController2 I need to change root view controller as ViewController2.
Now when I need to remove Navigation2 at that time change root as ViewController1.so,as per your question you need to change root view controller.

Why doesn't the first navigationcontroller in my storyboard have an effect on the tableviewcontroller?

My Storyboard is setup as:
UIViewCont
/
NavigationController -> UIViewContr -> UIViewContr ----- UIView Contr
\
NavCont
\
TableViewController
The last three controllers (2 x UIView and 1 x TableView) use "show" segues from three different buttons. And the TableView controller is embedded in the NavCont.
Because the first controller is a NavController every UIViewController has a back button except the TableViewController.
I've been reading up about it but can't figure out why. Other than each Navigation controller is it's own stack and kind of starts again so you can't just navigate back from a 2nd or 3rd navigation controller. But not sure.
Thanks.
Using a navigation controller resets the navigation stack tracking, so your table view does not have a back button because it is effectively a new root. If you create a view controller that the table view segues to, it will have a back button because it is part of the (inner) navigation chain and not the root.
It is not apparent from your example what you are trying to do or why you have the inner navigation controller instead of just relying on the original navigation stack. There is one option you can try. The root view of a navigation stack should have the navigation bar, and you can drag bar button items onto it, allowing you to unwind back to the previous state.

How to navigate back from a navigation controller on the storyboard in xcode

I've got an initial view controller InitialViewController with a button "List" (and a few other random buttons).
Clicking on "List" segues to a UITableViewController that is embedded in a navigation controller. And that is all sweet.
But once the UITableViewController is loaded there is no "back" button to navigate back to InitialViewController.
I was just wondering what my options were. On the storyboard I've used a "Navigation Item" and "Button Bar" and i'll hook that up programmatically to navigate back.
I just wasn't sure if an unwind segue was an option or if anyone had better ideas.
Thanks.
The reason you don't see a back button when your UITableViewController is loaded is because it is the root view controller for the navigation controller that it is embedded in. As such, the NavigationController has no other view controller in the stack that it can go back to.
Instead of the TableViewController, embed your InitialViewController inside a NavigationController and that should add a navigation bar with Back button to your TableViewController.
If you don't want to show the Navigation Bar in your InitialViewController, you can hide it using the following steps:
In your storyboard file, select the InitalViewController
Open the Attributes inspector and set Top Bar to None
Hope this helps!

Is Initial View Controller does work?

I have a viewcontroller and a tab bar controller. I want to change view controller as initial view controller and create a segue to show tab bar controller.
I have tried to set the new initial view controller. There are 2 ways. First, check the tick box "Is Initial View Controller". Second, drag the arrow to new screen. It does not show any error, but it shows the tab bar controller as usual and I can't find the view controller either.
Anyone know how to what is going on. Please tell me to fix. Thanks
You need to use a UINavigationViewController and connect it up in the hierarchy in a similar fashion to:
The leftmost view is the "view" that you mention, which needs to show the UITabViewController.
I've added a button for ease of use.
The next along (send from the left) is the UINavigationViewController. No settings on here need to be set etc... it's pretty much "plug and play" as to put it.
The next view (third from the left) is the UITabViewController (with corresponding views to it's immediate right).
The connection between the UINavigationViewController and the UITabViewController is "rootViewController" as the Tab View is the "root view controller" e.g. the primary view controller.
The segue between the first view, and the navigation view controller is merely a "show" segue. I liked directly between the button and the navigation controller in Xcode.
Hope this mash-up helps!
Edit I wrote a quick mask up of what I posted in the images for you to play with: https://dl.dropboxusercontent.com/u/61211034/Stackoverflow/NavgationViewController.zip
Based on your storyboard's image, looks like you don't have any NavigationController embedded to your root LoginViewController, try this:
Select your LoginViewController on your storyboard
Then in xcode Menu bar at the top, go to Editor -> Embed in -> Navigation Controller (as you can see in the image below)
Then your NavigationController will be set as your Initial View Controller, and see your LoginViewController be displayed and work as expected your segue.

Storyboard: inferring navigation bar after changing segues

I am developing a navigation-based app with few views. In the Storyboard, I have a Navigation Controller that points to my main ViewController ("center" view of my app) that points to other views with segues.
At first I wanted this segues to be push but it didn't work properly (the buttons were hardly responding), I've switched to modal (as advised here). Now the segue works fine but whenever I use modal segue, the navigation bar in view it points to disappears (I've tried with other configurations - the navbar is being shown on Storyboard but doesn't work on Simulator).
Where am I making mistake?
With a modal presentation your view controller is no longer part of the UINavigation stack. You can drag in a new UINavigationController, display that as a modal view and have your view controller class the root view controller of the navigation controller.
As suggested by JoePasq, "Have your view controller class the root view controller of the navigation controller". Select your view controller which you want to set as Root screen and goto Editor/EmbedIn option and select navigation controller. You will get a navigation-controller embedded with your root view controller. Instead of setting up segues you can change your screens programmatically in your program. In your method for button click event write a similar code as below;
- (IBAction)okPressed:(id)sender {
UIStoryBoard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle: nil]; //MainStoryboard is the name of your storyboard
SecondViewController *secondView = [storyboard instantiateViewControllerWithIdentifier:#"sView"];
//sView is the identifier name set by the user, (present inside Attribute Inspector - View Controller)
[self.navigationController pushViewController:secondView animated:YES];
Let me know if this works or there is also another way to do it.