I am creating a Project In which I have FrontViewController And SlideOutMenu. On clicking MenuItem I want according view in the FrontViewController's subview. The FrontViewController is having Storyboard and all the subviews are created in .xib. And I am getting subview but not getting the navigation bar as in the Storyboard.
So my question is:
How to get the same navigation bar in the xib as the storyboard has?
I have tried:
UINavigationController *navigationController =
[[UINavigationController alloc]
initWithRootViewController:bookingViewController];
[_swReveal
pushFrontViewController:navigationController animated:YES];
But I am not getting anything.
Related
I've a UIViewController which loads it's view form a Xib file. In my AppDelegate.m I would like to initiate my rootViewController with that myViewController and I would like that the title of the navigtionItem is set by taking the NavigationBar view which is part of the Xib file of the myViewController:
MyViewController *myViewController = [[MyViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myViewController];
According to the documentation
Each time the top-level view controller changes, the navigation controller updates the navigation bar accordingly.
In my setup this seems not to happen or I haven't indicated that my NavigationBar view is actually the navigationBar to consider.
How can I tell the NavigationController to update it's navigationItem content (title, left and right bar buttons) according the NavigationBar view which is part of the Xib file from myViewController?
Update
My Xib layout looks like this:
I know I can set those items in code by:
self.navigationItem.titleView = ...;
self.navigationItem.leftBarButtonItem = ...;
But I want them do design in the Xib file of the ViewController and they should be used in the NavigationController.
In ViewWillAppear method in your ViewController set-
self.navigationItem.title = #"Title name";
Also in the same way you can set self.navigationItem.leftBarButton and RightBarButton items
Adding a UINavigationBar view to the main UIView doesn't do what you think it does. It merely adds a navigation bar view there in the view, it does not tie into the UINavigationController.
If you use a storyboard, you can add the UINavigationItem as a child of the UIViewController. But since you are not using a storyboard, the easiest way to do it is to update the navigationItem in viewDidLoad.
Sidenote: Apple does not recommend using viewDidLoad to setup the navigation item. If you really want to do it the proper way, you can for example do it in the navigationItem getter.
- (UINavigationItem*)navigationItem
{
// get super navigation item
UINavigationItem *navItem = [super navigationItem];
// do stuff
return navItem;
}
I've added a navigation bar to my view controller and added text to the Back Button option under Attributes Inspector but I'm not getting a back button when I run the app.
Picture of the setting: http://imgur.com/QTN0sPt
Picture of the storyboard: http://imgur.com/n4pmgeb
Picture of app when I run: http://imgur.com/fidq2dF
Any suggestions?
Your View Controller should be embedded in a navigation Controller. By doing this a back button is added by default in the View Controller.
Embedded your controller in UINavigationController and then do your operation Push or pop or etc
Controller * objController = [[Controller alloc] initWithNibName:#“controllernib” bundle:nil];
UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController: objController];
The root View View controller is Navigation controller and its first level is a TabViewController.One of the tab item is a TableViewController.
Here is the relationship:
However the navigation bar overlap the table view:
I have also set simulated metrics,So what can be the problem??
Thanks for any help.
Simulated metrics are just that, simulated. They do not actually apply to the compiled product.
To fix this, I find it easiest to set the edgesforextendedlayout with the various values of edge values. Usually all but the top.
The rootViewController should be the UITabBarController. Follow this code:
1.Make the UITabBarController the rootViewController in the application delegate or in your main.storyboard set it as the initial View Controller.
2.In the UITabBarController.m place this code there to create the UINavigationController with a UIViewController embeded inside of it.
//Inside UITabBarController.m
- (void)viewDidLoad {
[super viewDidLoad];
UIViewController *vc = [[UIViewController alloc]init];
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:vc];
self.viewControllers = #[navCon];
}
Get rid of the navigation controller in the beginning and, instead, embed the tableviewcontroller inside a navigation controller.
(Select the view controller -- Click "editor" > "embed in" > "navigation controller").
Make sure the tab bar controller is the root view controller as well
This will also fix the overlapping issue
Im having difficulty getting the titles of the navigation bars to display along with the buttons within my tabBarController interface. Im creating the tabBarController programmatically. Here is the screenshot for reference.
I have tried putting self.navigationController.navigationBarHidden = YES; within the alloc/init method of the tabBarController which is allocated in the appDelegate and set as the windows rootViewController. I've also tried to set its title with this code self.navigationController.title = [[self.viewControllers objectAtIndex:self.selectedIndex]title ];. I have also tried using the same code within the viewDidLoad method of my tabBarController class. Within the UITabBarController's alloc/init method I do have this code to set the nav controllers that I have added to the viewControllers array.
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:contactsTblView];
nav2.title = #"Contacts";
nav2.navigationItem.title = #"Contacts";
nav2.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemContacts tag:2];
nav2.delegate = self ;
The title that appears in the navigation bar is the title of the currently showing view controller (the top of the navigation controller's stack). You should set the title of the individual view controllers embedded in the navigation controller, not the navigation controller itself.
I have an UI Navigation project with tab bar, each tab bar is contain XIB and ViewController, the project is loaded each ViewController from the App delegate by this method :
MyFourthView *fourthViewController;
fourthViewController = [[MyFourthView alloc] initWithTabBar];
localNavigationController = [[UINavigationController alloc]
initWithRootViewController:fourthViewController];
[localControllersArray addObject:localNavigationController];
Now I am trying to add storyboard to my project, and load it from the app delegate programmatically to be a fifth tab bar view, but I don't know how I can do that? because there is no XiB in the storyBoard so the above method isn't work ?
If the fifth navigation controller you want to add to your tab bar is the root/initial viewcontroller in your storyboard you can instantiate it like this:
UINavigationController *fifthNavigationController = [[UIStoryboard storyboardWithName:#"yourstoryboardname" bundle:nil] instantiateInitialViewController];
If its not, give it a storyboard id and instantiate it like this:
UINavigationController *fifthNavigationController = [[UIStoryboard storyboardWithName:#"yourstoryboardname" bundle:nil] instantiateViewControllerWithIdentifier:#"storyboardIdOfYourNavController"];
Apple documents switching to using Storyboards here:
http://developer.apple.com/library/ios/#releasenotes/Miscellaneous/RN-AdoptingStoryboards/index.html