I am basically presenting my DetailViewController as modalView.In the modalView navigation bar is never visible, though I am not hiding it any where.Please help!
WriteReviewController *newReview = [[WriteReviewController alloc] initWithNibName:#"WriteReviewController" bundle:nil];
UINavigationController *modalNavController = [[UINavigationController alloc] initWithRootViewController:newReview];
// This is intended to be presented in another view controller class
modalNavController.navigationBar.barStyle = UIBarStyleDefault;
[self.parentViewController presentModalViewController:modalNavController animated:YES];
[modalNavController release];
This code worked for me
Related
When I present a view controller modally:
// Display the nav controller modally.
[self presentModalViewController:theNavController animated:YES];
The navigation bar is covered up the view the pops up!
How can I get the navigation bar to not get covered up??
Thanks in advance!
The answers can be found at iPhone: Show modal UITableViewController with Navigation bar
and
UINavigationBar refuses to show in Modal View Controller!
You need to wrap the UIViewController in a UINavigationController, and then present the navigation controller:
AccountViewController* accountViewController = [[AccountViewController alloc] initWithNibName:#"AccountView" bundle:nil];
...
// Initialize properties of accountViewController
...
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:accountViewController];
[self.navigationController presentModalViewController:navController animated:YES];
[navController release];
[accountViewController release];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewContorller:someViewController];
[self presentModalViewController:navController animated:YES];
I am working with push notifications. i am trying to create and push a DetailView in the navigationController when action button in notification is clicked. but navigationController is nil. how can i put that DetailView in the navigationController? I want to push RootViewController in the navigationController and then the DetailView. how can i do that?
in AppDelegate:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
RootViewController *controller = [[RootViewController alloc] init];
//getting warnings here.(Unused variable navigationController)
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
[controller doStuff];
[controller release];
}
in RootViewController:
-(void)doStuff{
[[self stories] removeAllObjects];
[self startParsing];
[self.tableView reloadData];
DetailViewController *detail = [[DetailViewController alloc] init];
//custom code
[self.navigationController pushViewController:detail animated:YES];
[detail release];
this is the code i m using right now. and plz notice that i have
[self.tableView reloadData];
Okay, now I am pretty sure I understand the issue. The problem is, you never manually set the navigationController property on a UIViewController. The navigationController property is nil if the view controller is not under a navigation controller and if it is, then the property points to it.
What you need to do, is when you display your root view controller, instead of directly displaying its view, add it to a navigation controller, then display the navigation controller's view. Like so:
RootViewController *controller = [[RootViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
//Here you would display navigationController.view somehow
So, after you have your root view controller in a navigation controller, in a method in root view controller you can do this:
DetailViewController *detail = [[DetailViewController alloc] init];
//Do whatever you need to do to set values on the detail view controller
[self.navigationController pushViewController:detail animated:YES];
The key thing is this: you need to put the root view controller into a navigation controller before you can access a navigation controller from within root view controller.
If your nav controller is nil, it needs creating and then you place things into it.
Try this:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[navController pushViewController:detailViewController animated:NO]; // or YES
If you start out with no UINavigationController and want to display it with more than one view controller in its stack, after initing the navigation controller you can set the viewControllers property to an array with the various view controllers you want.
edit: some example code:
UINavigationController *navController = [[UINavigationController alloc] init];
NSArray *viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
[navController setViewControllers:viewControllers animated:NO];
After doing that, your navigation controller will have viewController2 on top and viewController1 behind it.
Alternately, you could do it this way:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController1];
[navController pushViewController:viewController2 animated:NO];
I am loading a Modal view controller using the following code in my RootViewController:
[self.navigationController presentModalViewController:accountViewController animated:YES];
In the accountViewController xib file, I have set a navigation bar. My MainWindow.xib and RootViewController.xib also have the navigation bar setup correctly. Additionally, my app delegate has setup the navigation controller (I assume) correctly:
UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.navigationController = aNavigationController;
[window addSubview:navigationController.view];
However, when I load my accountViewController the UINavigationBar is nowhere to be seen. Is it not possible to show a UINavigationBar in a modal view? I was planning to use it to hide the back button, and add a right button...
sha's answer is correct, but I'm giving my own answer to expand on it with a code example to make it clear.
You probably want something like:
- (void)showAccountViewController
{
AccountViewController* accountViewController = [[AccountViewController alloc] initWithNibName:#"AccountView" bundle:nil];
...
// Initialize properties of accountViewController
...
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:accountViewController];
[self.navigationController presentModalViewController:navController animated:YES];
[navController release];
[accountViewController release];
}
You need to push not viewController but navigationController that has viewController inside.
You can also set the presentation style in the Attribute Inspector to "Current Context". Modal View will not cover the Navigational Bar.
If you have a UINavigationController's UIViewController present a UITableViewController (TVC) modally, is there a way for the TVC to display the UINavigationBar of its parentViewController? Or, should I have it create a new UINavigationBar, item, buttons, etc. for the modal TVC?
I would just instantiate a UINavigationController right before you present your modal.
YourViewController *modalViewController = [[YourViewController alloc] initWithNibName:#"foo" bundle:nil]
UINavigationController *tmpNavController = [[UINavigationController alloc] initWithRootViewController:modalViewController];
[modalViewController release];
[self.navigationController presentModalViewController:tmpNavController animated:YES];
[tmpNavController release];
This is just back-of-the-envelope - I wouldn't copy and paste that code w/o a double-check!
Hi I have a modalViewController that I am popping up using
[self presentModalViewController:myController animated:YES];
I have an event occurring within myController which I would like to result in another controller being pushed onto the navigation stack ON TOP OF myController (which again has been presented modally). How can I do this?
I have tried the following from within myController:
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:self];
NewController* n = [[NewController alloc] init];
[navController pushViewController:n animated:YES];
[n release];
This does not work however....
First create your second modalViewController
NewController* new = [[NewController alloc] init];
then create navigaitonController like this
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController: new];
navigationController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
then present your navigationController as modalview controller
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
Here you go. Hope it helps.
If i understand right you want to display new navigation stack on top of modal view.
If it is right I think it won't be possible. Modal view is a top one. Even if you'll push new ViewController to the "parent" navigation stack - it won't be available until you'll quite from your modal view.