Using a UINavigationViewController on its own - iphone

In my application which is based on a tabbar view controller with many uinavigationviewcontrollers for each tabbar items, I want to present at some point (at application launch) with a call to presentModalViewController that contains a uinavigationcontroller as a root so the user can do a few things... when he or she is finished, the Done button at the top right corner can be tapped to dismiss the modal view controller and then return to the base tabbar view.... How can I do that with Interface Builder ?

In XCode, create a new View XIB file and open it in Interface Builder. In this xib file, delete the View and drag a UINavigationController into it's place.
Then, in your view controller code, something like
UINavigationController *controller = [[UINavigationController alloc] initWithNibName:#"ModalViewController" bundle:nil];
[self presentModalViewController:controller animated:YES];
[controller release];
Will load your XIB and present it.
Hope this helps, any other questions don't hesitate to comment on this answer!
S

Related

How to use a Button in Container View's Navigation Controller to go back to last view

Hi I am a newbie in iOS
In my project I didn't want to use a Navigation Bar because of the tint effect, so I used a container view to create something similar except for the back button I used an image with a button on the back.
I have used a Container View(connected to a Navigation Controller) to include a label and a button with an image on top of that button. I want the view to go back to the previous view when I click the button (the one inside the container view's navigation controller). I tried the usual [self.navigationController popViewControllerAnimated:YES]; but with no result. How do I execute this task?
If you are using
[self presentViewController:yourVC animated:YES completion:nil];
to present your View Controller, then you should use
[self dismissViewControllerAnimated:YES completion:nil];
to dismiss your present View Controller and to go back to the last View Controller.
the view which you want to push to connect with UINavigation Controller pls clear that you is your app navigation based app, if not pls add it in App Delegate
ViewController *ViewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:ViewController] autorelease];

Loading another UIView directly from the main ViewController

I am in the process of creating an application. In the main ViewController I have created the menu. But I want to have a login screen (UIView) to appear before the menu is visible.
But because the menu loads as soon as I run the application I have decided to create another UIView controller and have that loaded on top of the main ViewController.
Therefore at the end of my main ViewController viewDidLoad I have added the following code to open on top of that view the login view
LoginPageView *loginPageView = [[LoginPageView alloc] initWithNibName:#"LoginPageView" bundle:nil];
loginPageView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:loginPageView animated:YES];
As I know the purpose of that code is to present another view, but unfortunately the login view does not appear. Only the main ViewController load.
Can anyone help me on that? Have you realised what exactly I want?
Thanks a lot
In the viewDidLoad method, the view exists, but there is no guarantee that the view is already part of the view hierarchy of your application. In fact, almost ain't.
What you can try is take that code in the viewWillAppear: or viewDidAppear:.
Make a UINavigationController. Use this as your window's root view controller. Set the UINavigationController to not show the navigation bar.
Set the navigation controller's child view controller to your login view controller.
When the user logs in successfully, create your main view controller and push it, like this:
MainViewController *mainVC = [[MainViewController alloc] initWithWhatever...];
[self.navigationController pushViewController:mainVC animated:YES];
When the user logs out, you can just do this to get back to the login VC:
[self.navigationController popViewControllerAnimated:YES];

add overlay view over all other views

how do you add an overlay view that goes over everything. eg over a tab bar controller, and a navigation controller?
thanks
Find the "top" view in your stack, and add a subview. eg
[self.tabBarController.view addSubview:myView];
The hardest part is finding the topmost view; with a tab bar, it will be its own view.
Add a window. That's what the popup keyboard and UIAlertView do, you can see that in this view dump.
Use a modal view controller. Have a read of this guide:
http://developer.apple.com/iphone/library/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html
Presenting the view controller itself is easy:
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:addController];
[self presentModalViewController:navigationController animated:YES];

iPhone SDK: Can't specify view to Navigation Controller

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.

Set a navigation controller without an app delegate

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.