UINavigationController from scratch? - iphone

I have a view based app that works well. (In other words, I'm not going to start over with a Navigation-Based App template.)
It's an immersive app of sorts and I'm trying to add a Table View that loads in a new view when a button is pressed.
The loading the nib part works, but I can't seem to be able to add a navigation controller to the new view. I want to see a navigation bar on top with a done button and an edit button. Also, I want to the Table View entries to be empty.
I added a new file like so:
File-> New File -> UINavigationController subclass. I checked the UITableViewController Subclass and With XIB for user interface.
All I see when the view is pulled up is a blank Table View. I am able to customize things in the view controller.
What can I do to make the table show a navigation bar and be editable? I need some direction here please.
EDIT: I'm working with the latest Public SDK. (XCode 3.2.2)

The navigation bar usually comes with a navigation controller, not with the table view controller.
You can add the navigation bar manually, but that will require altering the table view, to change it to just a regular view with a table view inside of it, and changing your table view controller to be a regular view controller that manually handles the table view stuff.
The simpler alternative is to wrap your table view controller inside of a navigation controller before you display it. Something like:
MyTableViewController *myViewController = [[MyTableViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myViewController];
[myViewController release];
//Now display navigationController instead of myViewController, using something like:
[self presentModalViewController:navigationController animated:YES];

Related

add a new tab containing a master-detail in iOS

I created an app using the Tabbed Application template (without using a storyboard) and added several tabs along with their functionality. Now I want to add another tab that will have Master Detail functionality. There doesn't seem to be a way to use the Master Detail template without creating a new app. I tried creating a new app with the Master Detail template just so I could look at the code it generates but I can't figure out how to incorporate that code into my existing tabbed app. How should I proceed?
You can do it like this... (Adding example to Phillip's answer)
MasterViewController *masterViewController=[[MasterViewController alloc] init];
UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:masterViewController];
[masterViewController release]; //if not ARC
tabbarController.viewControllers=[NSArray arrayWithObjects:navigationController,
viewController1,
viewController2,
//More view controller objects,
nil];
[navigationController release]; //if not ARC
MasterViewController may contain a UITableView as subview or it may simply be a UITableViewCotroller (as you need Master-Detail flow.).
On an iPhone, a master/detail structure is basically a table view controller embedded in navigation controller and another custom view controller that is pushed when selecting a cell in the table.
If you're doing this in code, init your table view controller, init the navigation controller with the table view controller as its root, and update the tab bar controller's viewControllers property.
to get your whished behaviour in storyboards drag a navigation control in and make THAT a 'child' of the tabbar

How to add a TableView with NavigationBar (Navigation Controller) to a View

I got a tabbed application like this:
and already set up everything like it should look, but it won't function yet. I already googled my problem and they said you first need to set up a NavigationController with the table view as rootView and then the NavigationBar but I really couldn't figure it out. Hope someone of you can help me.
Based on your response to my comment on your question here is what you should be doing:
First off, in order to make it look like the settings app table, you will need to change the style of your UITableView to UITableViewStyleGrouped.
Your hierarchy will consist of the following:
The viewcontroller that is actually added into your UITabBarController viewControllers array(since I see you have a tabbar as your lowest level of navigation) should be an UINavigationController. The root viewcontroller of the navigation controller should be the uiviewcontroller subclass you made that contains your table view. (let's say it's called SettingsViewController)
SettingsViewController *settingsViewController = [[SettingsViewController alloc] init];
UINavigationController *settingsNavController = [[UINavigationController alloc] initWithRootViewController:settingsViewController];
You will probably need to create a different UIViewController subclass for each type of detail pane you're going to want (if they have different functionality).
In the didSelectRowAtIndexPath UITableViewDelegate function, you will create the appropriate detail viewcontroller and push it onto your navigation stack.
Let's say you have a volume settings view controller as an example. The following is the code you would have in the function I just mentioned. Keep in mind you also need to actually check the index and/or section of the selected row to figure out which detail view should be shown.
VolumeSettingsViewController *volumeSettings = [[VolumeSettingsViewController alloc] init];
[self.navigationController pushViewController:volumeSettings animated:YES];
By default, this will function pretty much like the Apple Settings app navigation. The navigation bar will automatically have a "back" button to take you back to the settings view.
If you are using a Storyboard, select your view controller, go to the "Edit" menu and choose, "Embed in Navigation Controller."
If not using story boards, assuming this will be done in code, you need to create things in a reverse order of their hierarchy - something like this:
Create an instance of the Einstellungen tab's TableViewController using initWithNibName:
Create a UINavigationController using initWithRootViewController: and setting the Einstellungen as the root
Create a UITabBarController and set your navigation controller as one of the view controllers of this tab bar controller
Add the tab bar controller as a subview to the main window in your application delegate
This will create this hierarchy:
Tab bar controller
->view controller: Navigation Controller -> root view controller: Einstellungen

Adding navigation controller to custom designed table view which have calender view

want my table to show up only half way from the bottom of the screen, the upper half meant for the calendar view. To do this, I added a table view through code using CGRectMake specifying the (x,y) co-ordinates I wanted it to start at.
Now, I want each row of this table to navigate to a new view. How do I make the navigation controller push my new view? I added a navigation controller to my main view
TaskDetailsViewController *detailViewController = [[TaskDetailsViewController alloc] initWithNibName:#"TaskDetailsViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
If you need to apply navigation from a view controller, that view controller should be a part of the navigation viewcontroller stack.
So what you have to do is instead of adding the rootViewController directly, You create a navigation controller, and set the rootViewcontroller to it(as rootViewController property). Once you set it, You can add navigation controller in place of rootViewController added previously.
Then on click you can use.
[self.navigationController push..... animated:..];
You can check it. If try to access the navigationController by self.navigationController currently it would be returning nil.

How is a navigation controller added to an existing view

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."

Navigating between views using Toolbar

In my app, I require the main page to contain a toolbar at the top of the view. This view has a tableView. So my application cannot have a NavigationController.
Problem
When I want to navigate to the other view on click of the tableview cell then I am using the "pushViewController:animated:" method but it doesnt seem to work.
I checked the connections in IB. They are fine.
How can I navigate between pages without navigation controller??
I do not want to use the modal view for other views.
Please Suggest some Method.
You can use an instance of UINavigationController without having it displayed and using it for navigation.
Load your first view controller with your instance of UINavigationController in your appDelegate implementation.
Like:
FirstScreenController *fsc=[[FirstScreenController alloc]initWithNibName:#"FirstScreenController" bundle:nil];
UINavigationController *navigation=[[UINavigationController alloc]initWithRootViewController:fsc];
navigation.navigationBar.hidden=YES;
[window addSubview:navigation.view];
Here FirstScreenController can be your view controller having the toolbar and tableview.If you want to display another view on any click of the tableviewcell, call it this way.
[self.navigationController pushViewController:secondviewcontroller animated:NO];