How do i create a navigationBar in UITableViewController in Swift?
ios, swift
Solution
You can not simplly add a `NavigationBar` to `UITableViewController` like that.
The simplest way to have `UINavigationController` and `NavigationBar` is to do it from Storyboard.
Steps:-
Drag the UITableViewController Object from Object Library to the Storyboard.
Highlight the UITableViewController, go to Edit -> Embed In -> Navigation Controller like the screen shot below:-
Go to File -> New -> File.. -> iOS -> Cocoa Touch Class, and create a Custom TableViewController class like below screen shot:-
- Finally, go back to storyboard and highlight the UITableViewController object. Under the identity inspector, choose the custom class that you have just created like the screen shot below:-
You may do whatever you want with the custom class file. You may also add a custom `UINavigationController` class as well if you want and you may attach the custom class to to the object inside the storyboard.
Problem
I am new to IOS, I would like to add a `UINavigationBar` to `UITableViewController`, I have tried this: ``` var navBar: UINavigationBar = UINavigationBar(frame: CGRect(x:0, y:0, width:320, height:80)) ``` then, ``` self.view .addSubview(navBar) ``` Thanks