I am working on a view based app in iphone, i want to show the Navigation bar when it is loaded, i am using [self.navigationController setNavigationBarHidden:NO animated:YES]; in viewdidload function, but it is still showing the same simple view without the navigation bar at the top, what's the problem
if you are using Xcode4 then do this in app delegate.
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
UINavigationController *navcontrol = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navcontrol;
You need to add the NavigationBar to your view.
calling this should sort it out
[self.view addSubview:navigationController.view];
Related
I have 3 tabs and main navigation controller. I implements with code:
UIViewController *monitorController = [[[MonitorController alloc] initWithNibName:#"MonitorController" bundle:nil] autorelease];
UIViewController *dashboardController = [[[DashboardController alloc] initWithNibName:#"DashboardController" bundle:nil] autorelease];
UIViewController *settingsController = [[[SettingsController alloc] initWithNibName:#"SettingsController" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:monitorController, dashboardController, settingsController, nil];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:self.tabBarController] autorelease];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
I want to change navigation title when I select another tap, but no variant (see below) not working (there are no any title at navigation controller):
self.title = DASHBOARD_TITLE;
self.navigationController.title = DASHBOARD_TITLE;
How I can resolve this problem?
The UINavigationController will display the title of the UIViewController it's currently displaying, that is why you are not able to set it directly.
You may try to change the title on your UITabBarController, but I'm not sure the navigation controller will update it's title after it first appeared on screen.
But, Do you really need that Architecture?
Usually the UITabBarController is the root viewController and if you need UINavigationControllers they are place inside the Tab that need to have navigation capability.
It was design to be use that way.
Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.
Quoted from UITabBarController Class Reference
Sorry I misread your question, what you have to do is to implement -tabBar:didSelectItem: from UITabBarDelegate protocol, and then change the title according to the pressed tab.
Or in the ViewWillAppear method of your controllers set the title, the way you were doing it
Hihi all,
I am pretty new in iPhone dev. I have follow some tutorial and created a tabbar application. Below is the code in the appdelegate implementation:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1 = [[ViewController1 alloc] initWithNibName:#"ViewController1" bundle:nil];
UIViewController *viewController2 = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
Then set the title and the image for the tab in each of the controller implementation.
My problem is that, example, in my viewController1, I need to navigate to viewController3, when I use presentModalViewController method to push the viewController3 in, the tabbar at the bottom will be disappeared.
While I tried to use the app delegate to refer to my tabBarController, and use tabBarController.navigationController pushViewController method, my viewController3 is not being pushed, and seems nothing happens.
I have tried to follow a few tutorial, but it's all required to drag in the navigationcontroller into the MainWindow.xib, which, in the xcode 4, MainWindow.xib doesn't exist anymore. How can i create the navigationcontroller from code so that the app can navigate between different view without hiding the tabbar?
Any comment is very much appreciated! Thanks in advance!
:)
If you want to use a navigation controller, you need to create a navigation controller. Since you're not using a XIB, you'll have to create it manually.
Since you want the tab bar to remain visible when you present viewController3, you need to make the navigation controller a child of the tab bar controller.
UIViewController *viewController1 = [[ViewController1 alloc] initWithNibName:#"ViewController1" bundle:nil];
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
UIViewController *viewController2 = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:
navController1,
viewController2,
nil];
Then when you want to present viewController3, do this:
// in some method of viewController1
[self.navigationController pushViewController:viewController3 animated:YES];
I am not very Sure but have you tried this??? Actually i am going to use XCode 4 soon, i am still using 3.2.8 version:-
WebViewController *viewController = [[WebViewController alloc]initWithNibName:#"WebViewController" bundle:nil];
viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:viewController animated:YES];
[viewController release];
See in this also the Tab bar will be removed when you navigate to your 3rd screen, you have to provide the navigation bar to come back.
Hope it helps.. :)
I have a UIView (menuView in code below) of size 320x218 inside a view. I want to load a navigation controller into this view. Im using the following code to do that:
MenuViewController *menuController = [[MenuViewController alloc] initWithNibName:#"MenuViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:menuController];
navigationController.navigationBarHidden = YES;
[menuView addSubview:navigationController.view];
[menuController release];
[navigationController release];
When I execute it, the root view is not displayed in that view. Only a navigation bar is displayed and the rest of the view is empty.
Edit:
I just placed an NSLog() in both initWithNibName: and viewDidLoad: of MenuViewController. The one in initWithNibName: gets called but the one in viewDidLoad: doesn't :S
Update:
I tried to push menuController to my navigationController thinking since its not appearing, it might not be on the stack. Exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing the same view controller instance more than once is not supported
call layoutsubviews do work.
[super loadView];
[self.view addSubview:navigationController.view];
[navigationController.view layoutSubviews];
I found the answer here:
UIViewController -viewDidLoad not being called
I had to add these lines of code after -initWithRootViewController in order to load the view of my root view Controller:
navigationController.navigationBarHidden = YES;
[navigationController setView:menuController.view];
You should not add the navigationViewController as an subview To your MenuViewController.
As the navigationViewController already already holds the MenuViewController.
Just display the navigationViewController.
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
ViewController *viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
navController = [[UINavigationController alloc]initWithRootViewController:viewController];
self.window.rootViewController = self.navController;
Try this code in your appdelegate method
I don't use IB much for creating my views, so I usually do everything programatically. I'm bascially pushing a viewController to a navigation controller and it seems the top part of the viewController is under the navigation bar. I'm trying to make the view fit correctly.
Here is my code:
navigationController = [[UINavigationController alloc] initWithNibName:nil
bundle:nil];
[window addSubview:navigationController.view];
viewController = [[UIViewController alloc] init];
//this code was just added to try and make it fit. It doesn't change anything
viewController.view.frame = [UIScreen mainScreen].applicationFrame;
[navigationController pushViewController:viewController animated:NO];
I would be careful using the init method with view controllers - instead look at initWithNibName:bundle:.
I have a menu screen that implements UINavigationController and on top of that screen, using presentModalViewController, I place another screen on which I want to have another UINavigationController. I have tried to implement another navigation controller to handle the new screen but I either get a navbar 1/8th the way down the screen and it crashes or nothing at all. I have tried [[UINavigationController alloc] initWithRootViewController:navigationConroller] with no success as well. I'm just using pushViewController to try and place the next nib on the stack which doesn't work. What am I doing wrong?
Although there are a lot of people saying on forums that Apple doesn't allow this I have got it to work. What you have to do is:
Map *mapScreen = [[[Map alloc] init] autorelease];
mapScreen.delegate = self;
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:mapScreen] autorelease];
[self presentModalViewController:navController animated:YES];