Azat Nugusbayev
Azat Nugusbayev

Reputation: 1421

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?

Upvotes: 4

Views: 8542

Answers (1)

Ollie
Ollie

Reputation: 1946

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];

Upvotes: 8

Related Questions