Initially I used the IB to drag a navcontroller onto my tabbar and then setting the root controller. However, I'm trying to create a nav controller without IB.
What I've done is created a navcontroller subclass that will be used in my tabbar. The nav bar does show up so I know that is working.
Now, I need to push a viewcontroller into the hierarchy. In the nav controller's viewDidLoad:
- (void)viewDidLoad {
InfoViewController *initialController = [[InfoViewController alloc] init];
[self.navigationController pushViewController:initialController animated:YES];
[initialController release];
[super viewDidLoad];
}
I get no errors, but nothing shows up in the navigation controller. Anyone know why?
What does your InfoViewController's init method look like? If you're using a nib to build that, then you need to call initWithNib, not init.
Create the viewcontroller when/where you create the navigation controller (and add them to it) then add the list of view controllers to the tabbar.
Related
I've created a storyboard that I want to display using my UINavigationController. The initial view in the storyboard is a UITableViewController so I have created a subclass of UITableViewController and set the class on the storyboard to match it.
I then try to display the storyboard like so:
StoryBoardView *newView = [[StoryBoardView alloc] init];
[self.navigationController pushViewController:newView animated:YES];
However my view is not shown for some reason. Please can someone help me?
When you push the view controller, you need to instantiate the view controller from within your storyboard, not just alloc/init a new instance.
StoryBoardView *newView = [[self storyboard] instantiateViewControllerWithIdentifier:#"<ViewControllerIdentifier>"];
Have you tried when viewing the storyboard, select your very first controller and tick 'Is Initial View Controller'?
That should start your app with that controller.
I have a navigation controller with a rootview.
The rootview contains buttons, which push new views onto the navigation controller correctly.
However, on this rootview, I also have subview (it's a scrolling preview like the appStore images, view made of 3 UIview items). On these UIViews, there is a button which I'd like to change the rootview navigation controller, like the other buttons.
At the moment, it builds and runs, but the new view is not pushed. Any ideas?
Click method on on the ScrollItem button:
MyViewController *newView = [[MyViewController alloc] initWithNibName:#"ManageMyPain" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:newView animated:YES];
... i guess it is because, self doesn't have a navigation controller, but the rootview does.
Thanks!!
The property "navigationController" is only being set in a view controller if he's pushed to the navigation controllers stack. your second view is a sub view of a push viewcontroller which means this property is NULL and will not do anything if you try pushing things to it.
Yes, it is because self.navigationController will be nil if you didn't push that controller on navigations stack or if you didn't set it manually.
So you just need to have reference to rootViewController.navigationController and then [navigationController pushViewController:newView animated:YES]; will work perfectly.
I am working on my first iPhone app and making good progress. But there is one thing I just don't understand.
When my app starts it displays a UIView with some functionality on it. This works fine. One of the buttons on that screen is supposed to load a new view (HistoryViewController) which contains a navigation controller.
The problem is… whenever HistoryViewController is loaded the app crashes because there is no view. It's true because in the xib-File I can't connect the File's Owner's view to anything:
http://www.freeimagehosting.net/image.php?1a3caa8b8d.png
I definitely have a lack of knowledge somewhere but after hours of research I have not been able to solve this problem.
Any hints?
Thank you!
Normally you would either:
click on that bottom line (History Table View Controller, "HTVC") and in the inspector window specify a NIB Name - which means you would first have to make a new NIB.
or
doubleclick that bottom line (HTVC), so the 320x480 preview window pops up, and then drag in a UIView from the library.
Using the first method, you tell the view controller to dynamically load the NIB as the view to connect, and using the second method you do this for the view controller using IB. The view you drag in will then show up as a child of that bottom line (HTVC).
edit to actually load the nib file you created, do this to push the view controller:
UIViewController *controller = [[UIViewController alloc] autorelease];
[controller initWithNibName:#"nibfilename" bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
substituting UIViewController for your own view controller class (if needed) and nibfilename with the filename of the nib (minus the extension!)
It's hard to tell what your problem is exactly, but I'll offer some advice.
When creating a navigation controller (or tab controller for that matter) in interface builder, its easy to not understand what is really happening, so my suggestion drop interface builder for a second and lets build it in code.
In general I really dislike building either UI Navigation Controller or tab view controller in interface builder, I really just rather build the views themselves and create the UINavigationController in code.
You have a view which shows the HistoryTableViewController which you want to be contained in a UINavigationController so the code to do this is:
- (void) showHistory
{
HistoryViewController *historyVC = [[HistoryViewController alloc] init];
// If you create historyviewcontroller in nib
// HistoryViewController *histroyVC [[HistoryViewController alloc] initWithNibName:#"myNib" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootController:histroyViewController];
[self presentModalViewContoller:navController animated:YES];
}
This will create a nav controller showing your history view controller as the root view controller. Can't be easier.
I have a view which contains a UIButton. When this is clicked, it calls a method that loads another NIB. Now, normally, that nib would load a view onto the stack, and everything would be fine. But, I am trying to load a Navigation Controller (so that I can have table views that are multiple levels deep), and all I get it errors.
What is the proper method for loading a Navigation Controller and putting it on the top of the stack?
As the other poster said you should create your Nav controller in your AppDelegate. If you are adding a new UIView to the stack like presentModalViewController you want to create the UIView then add the Nav Controller to it. If you don't want nav controller on that screen but the next just use the navController.hidden property I think it is.
To add the nav controller to the view do this:
NoticesView *noticesScreen = [[[NoticesView alloc] init] autorelease];
noticesScreen.delegate = self;
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:notices_screen] autorelease];
[self presentModalViewController:navController animated:YES];
Hope that helps towards your question. Still trying to find out exactly what your doing
Create the navigation controller in the app delegate. Push your mapview onto the stack as the first view. Push your tableview onto the stack as the second. If you started with a view-based app template, you won't have a navigationcontroller instantiated at all. (Been there done that) the easiest way out of this is to use xCode to make a navigation based applcation and then copy the code out of that. If you do already have a navigation controller, then just push the view controllers as above.
I would like to show a Navigation Controller after clicking a button. Every tutorial assumes the navigation controller will be the first screen so it links it to the App Delegate, but App delegate only appears at MainWindow.xib.
How do you guys add a navigation controller to a view different than the MainWindow?
Thanks!
Here is some sample code to expand on Roger's answer. The following method is linked to some user interaction on the current view controller (to compose an email for example). This will give the compose view the navigation bar across the top instead of coding buttons inside your custom view.
-(void) composeButtonPushed: (id) sender {
ComposeViewController *controller = [[ComposeViewController alloc] initWithNibName:#"ComposeView" bundle:nil];
UINavigationController *composeNavController = [[UINavigationController alloc] initWithRootViewController:controller];
[self presentModalViewController:composeNavController animated:NO];
}
UINavigationController is to navigate a heirarchy of views with UIViewControllers. If you don't have a root UIViewController, it won't work (and doesn;t make sense). If you do have a UIViewController, you simply send a - (id)initWithRootViewController:(UIViewController *)rootViewController init message to a new navigation controller passing in your UIViewController.