Navigation Controller - How to Add in Another View

2019-09-06 09:54发布

I'm relatively new to iOS programming but I'm learning bit by bit. I've got two nib files, one is my HomeViewController and the other is called 'ReceiptTableViewController'. The HomeVC should not have a top nav bar but the ReceiptTableVC should, with a title and 'back' where the user can swipe to go back to HomeVC.

How would I go about adding this? I've dragged the Navigation Controller to the side of my ReceiptTableVC in the nib file.

I've searched for various answers but some contradict each other as the authors use different versions of Xcode, and some start with storyboards, etc.

Any help is much appreciated!

  • I haven't used storyboard

1条回答
可以哭但决不认输i
2楼-- · 2019-09-06 10:56

You can use this method to decide whether your navigationBar show or not in your viewController.[self.navigationController setNavigationBarHidden: animated:];

In your AppDelegate:

UINavigationController *naviController = [[UINavigationController alloc] initWithRootViewController:homeController];
naviController.navigationBarHidden = YES; //set home controller navigation bar hidden.
self.window.rootViewController = naviController;

Then in your ReceiptTableViewController's viewDidLoad method:

[self.navigationController setNavigationBarHidden:NO animated:NO]; // show the navigation bar.

This is how to declare a UINavigationController programmatically. You can have a try.

查看更多
登录 后发表回答