iPhone: Show modal UITableViewController with Navigation bar

前端 未结 6 1135
温柔的废话
温柔的废话 2021-01-30 00:10

I am showing a modal view which is a UITableViewController class. For some reason it won\'t show the navigation bar when I show it. Here is my code:



        
6条回答
  •  天命终不由人
    2021-01-30 00:26

    When you present a modal view controller it does not use any existing navigation controllers or navigation bars. If all you want is to display a navigation bar, you need to add the navigation bar as a subview of your modal view and present it as you're doing.

    If you want to present a modal view controller with navigation functionality, you need to present a modal navigation controller containing your detail view controller instead, like so:

    SettingsCreateAccount *detailViewController = [[SettingsCreateAccount alloc] initWithStyle:UITableViewStyleGrouped];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
    [detailViewController release];
    
    navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:navController animated:YES];
    [navController release];
    

    Your modal controller will manage its own navigation stack.

提交回复
热议问题