GFK76
GFK76

Reputation: 3

How to make tableview navigation at top

Can anyone please point me in the right direction? I want to make navigation at the top of a tableView like in attached image. Also how do I add the title at the top?

Below is the image:

enter image description here

Upvotes: 0

Views: 100

Answers (3)

rbaldwin
rbaldwin

Reputation: 4858

  1. Use a ViewController, not a TableViewController.
  2. ViewController -> Editor -> Embed In -> Navigation Controller
  3. You can set the title in Interface Builder or in Code
  4. Create a Horizontal StackView at the top of your view set top, leading, trailing constraints to 0, and a height.
  5. Inside your StackView add a UIButton "<", UILabel, UIButton ">", and connect actions and outlets in your ViewController code
  6. Set the StackView Distribution to Fill Equally
  7. Add a TableView and TableViewCell below your StackView and set constraints to fill the view.

enter image description here

enter image description here

In viewDidLoad:

    self.navigationController?.title = "History"
    self.navigationController?.navigationBar.barTintColor = UIColor(red: 74.0/255.0, green: 124.0/255.0, blue: 199.0/255.0, alpha: 1.0)
    self.navigationController?.navigationBar.isTranslucent = false
    self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor : UIColor.white]
    self.navigationController?.navigationBar.tintColor = UIColor.white

enter image description here

In relation to your further question below. Yes you can still do this if you are coming from a TabBar Controller:

enter image description here

Upvotes: 1

Saikrishna Kumbhoji
Saikrishna Kumbhoji

Reputation: 47

Select your View Controller in Storyboard

In the Top Menu go to Editor-->Embed In-->Navigation Controllerenter image description here

Then Automatically Navigation Bar Appers on the top of Your View Controller

To Add Title Select Navigation Bar in View Controller then in Attributes Inspector you can give the Titleenter image description here

Upvotes: 0

Huzaifa ameen
Huzaifa ameen

Reputation: 143

In xcode choose Editor > Embed In > Navigation Controller, then you can see the title on the top of your tableview, then search "nav item" and drag it to top of tableview navigation, and put the title text from setting. I hope this will help you.

Upvotes: 0

Related Questions