create navigation bar for tableView programmatically in objective-C

后端 未结 2 773
挽巷
挽巷 2021-01-24 17:37

I want to create navigation bar for my table view controller class programmatically would you please help me? I couldn\'t fix it!

Thanks in advance! I\'m really new to i

相关标签:
2条回答
  • 2021-01-24 17:58

    these three lines

    ViewController *vc = [[ViewController alloc]init];// or UITableVC as which VC you have in your file
    UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:vc];
        [self.window addSubview:navController.view]; // this is an important line if missed out dont show navController
    

    should be added after

     [self.window makeKeyAndVisible];
    

    in appDelegate.m didFinishLaunchingWithOptions method

    0 讨论(0)
  • 2021-01-24 18:14

    You dont create a navigation bar for a table view controller, what you should do is create a navigation controller and set the table view controller as its root

    UITableViewController *myTableViewController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
    UINavigationController *tableViewNavigationController = [[UINavigationController alloc] initWithRootViewController:myTableViewController];
    
    //use the navigation controller here instead of how you had used the table view controller
    
    0 讨论(0)
提交回复
热议问题