Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS. How can I embed in NavigationController in .xib?

I have .xib(not .storyboard) file in which I have an UIView which also has an UITableView inside of it. So, now I want to add navigation feature, but I can not embed a navigationcontroller like in this tutorial http://www.appcoda.com/use-storyboards-to-build-navigation-controller-and-table-view/ because I use .xib not a .storyboard.

How can I add navigation feature to my app?

like image 815
Azat Nugusbayev Avatar asked Feb 07 '23 10:02

Azat Nugusbayev


1 Answers

You can add it programmatically instead.

For example:

// Swift    
let navController = UINavigationController(rootViewController: Your View Controller)

// Obj-C
UINavigationController *navControler = [[UINavigationController alloc] initWithRootViewController: YourViewController];

Then either push/present the navigation controller depending on when you're planning on showing it.

Having looked at the tutorial, I'm assuming you're going to be showing the navigation controller as the first screen, in which case you can add it to the AppDelegate like this.

// Swift
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.makeKeyAndVisible()
self.window?.rootViewController = navController

// Obj-C
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
[self.window setRootViewController: navController];
like image 87
Ollie Avatar answered Feb 13 '23 06:02

Ollie