Top bar not showing for current ModalViewController

I created a subclass of UIViewController called addItemToListViewController. I also chose to add "xib" and just created a simple page with a few shortcuts and a text box. In the interface builder, I selected โ€œTop bar - navigation barโ€, so when it is pushed onto the stack when the application starts, it will have a top bar that will correspond to the initial main window. In the interface builder, it shows the top border, but when I run the application in the simulator, the top panel is missing when the view is displayed.

Here is the code I posted on the root controller to represent the view controller

- (IBAction)addButtonPressed:(id)sender { AddItemToListViewController *addItemToListViewController = [[AddItemToListViewController alloc] initWithNibName: @"AddItemToListViewController" bundle:nil]; [self presentModalViewController: AddItemToListViewController animated: YES]; [AddItemToListViewController release]; } 

I can only have a top bar if I manually add the navigation bar to xib. If I have to add a navigation bar to my xib, what is the purpose of the Top Bar attribute?

+4
source share
3 answers
 - (IBAction)addButtonPressed:(id)sender { AddItemToListViewController *addItemToListViewController = [[AddItemToListViewController alloc] initWithNibName: @"AddItemToListViewController" bundle:nil]; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:addItemToListViewController]; [self presentModalViewController: navController animated: YES]; [AddItemToListViewController release]; [navController release]; } 
+5
source

This "top bar - navigation bar" in InterfaceBuilder is known as "Simulated Metric". This will help you build your presentation at the right interval when other visual elements - a status bar, navigation bar or tab bar - can consume part of the deviceโ€™s on-screen real estate. This actually does nothing but reduce the vertical dimensions of the view defined by the NIB. The goal is to help you post your opinion, and not create a component that will appear in your application.

If you want a navigation bar, you have two options. The first choice is to use the navigation controller (from which your original view should be the root) and call

 [self.navigationController pushViewController:newVC animated:YES]; 

The process of setting up a navigation controller, etc. is non-trivial, and you should do some searches to find the best way to do this for your application. For a simple application, especially if you are just learning iOS, you can use the Navigation Application template when creating a new project. With navcon, you get all the bizarre behavior that is usually associated with this top bar - an automatic return button, fantastic left / right scrolling when moving to a detailed view, etc.

The second option is to place the โ€œfakeโ€ navigation bar in a detailed view using the Navigation Bar object. You can find this object, as well as some other related objects, in the lower half of the Utilities window (rightmost) in Xcode. Just drag the object into your XIB and blammo, you have a gray bar 44 pixels high. This navigation bar is similar to what you get when you use the navigation controller, except that you don't get stack functionality; you can add buttons left and right, change the title, tint it to a specific color, etc.

+4
source

xib does not know that you will use the controller as a modal representation, since it can also be used for the normal view, which can display the top panel. Only when you click a view will it use or ignore the display of this top panel.

In short: its there if you use xib for the usual look :)

+1
source

All Articles