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.
Related
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.
In my application i want to add a viewcontroller with nib on top of tabbarviewcontroller using storyboard.
for eg; when the application launch for first time i want to show that view controller for once and after that when ever user start the application it should show the tabbarviewcontroller. and not the viewcontroller.
following is my code
-(void)viewDidAppear:(BOOL)animated
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateInitialViewController];
[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:vc animated:YES];
}
I'm a little confused with how you described what you want. There are a couple of ways to do what you want and depending on how you want things to flow.
Storyboard
If you stay in the storyboard, you can add a UIViewController - in front of your tabbar (to the left of) controller. Basically, add a UIViewController and move the start arrow to it. then create a segue from it to your tabbar controller. You can bring in the tabbar controller via a push segue or even as a modal segue if you want.
You would have to move your xib file into the storyboard.
It would flow like this: UIViewController -> UITabbarController -> Rest of your app.
In this model, the first view controller would always be available on launch.
Another strategy - trying to keep things simple is to use the first view controller attached to the tabbar. It would align with the left most tab.
That view controller gets instantiated and put on screen by the tabbar controller first under normal conditions. You can add code in that UIViewController in the ViewDidLoad or ViewDidAppear methods to instantiate and put up the modal view using either a storyboard or a nib file.
Finally, the last way I can think of would be to load the nib file from your app delegate then display your tabbar from the storybook as a modal. I think this approach is the least desirable, but doable.
hope that helps. good luck.
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.
My application is view based app. First view is login view. After login view i have MainMenuCcontroller which has a tabBarController:
#interface RunnoMainMenuController : UIViewController {
IBOutlet UITabBarController *tabBarController;
}
From login view controller, i am going to MainMenuController using this line of code:
[self presentModalViewController:mainMenu animated:YES];
this controller has 4 tabs. Now i need to do some stuff in viewWillAppear of a tabBarItem. viewWillAppear is not called when i tap a tabBarItem. I have a button in one of those tabBarItem's view which pops up a table view controller using presentModalViewController. This tableView uses dismissModalViewControllerAnimated:YES to disappear it. When i pop up this tableview and dismiss it then viewWillAppear of every tabBarItem works fine. If i will dismiss modalViewController in MainMenuController then it will again go back to login view. How can i dismiss modalViewController without leaving current view or any other solution? Thanks in advance.
You may need to consider how your views are presented. The tab bar controller should always be the window's root view controller. From the Apple docs:
When deploying a tab bar interface, you must install this view as the
root of your window. Unlike other view controllers, a tab bar
interface should never be installed as a child of another view
controller.
Rather than present your login view as the root view and the tab bar as a modal view controller, try it the other way round. The tab bar controller as root, with the login view as presented as a modal view controller from the view controller of whichever tab is shown initially. Dismissing this will then reveal the tab bar controller.
I have a tableView and want to add a new viewController so that when the user selects an item the new view shows an image and the bar at the top will allow the user to go back to the tableView.
This navigation bar at the top will be present in both views. Is it also possible to add a button e.g. share to it and link my own actions to the button?
Thanks.
Your tableView should live inside a UIViewController subclass that is itself inside of a UINavigationController. You can get this structure set up for you by selecting the "navigation-based" app in the project creation wizard. Or you can create this structure yourself in code. In your app delegate, create a UINavigationController, and set your app's first ViewController as the root view controller. Then pushing and popping view controllers is easy, just call:
MyDetailVC *vc = [[[MyDetailVC alloc] initWithNibName:#"MyDetailVC" bundle:nil] autorelease];
[self.navigationController pushViewController:vc animated:YES];
EDIT: so, to clarify, you don't "add navigation controllers to existing views," you "push and pop instances of your view controllers on to the navigation controller's stack."