Swift Add Footer View In UITableView

2 Solutions Collect From Internet About “Swift Add Footer View In UITableView”

Using StoryBoard

In TableView You can drag UIView, it will set as FooterView if you have more then 0 prototype cell. After Drag you can see it in tableview hierarchy as subview.Now, you can add label button on that View, you can also set IBAction into ViewController Class File.

Programmatically

Follow 3 Steps

  1. Make one custom view with button,

Swift 3.X / Swift 4.X

let customView = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 50))
customView.backgroundColor = UIColor.red
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
button.setTitle("Submit", for: .normal)
button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
customView.addSubview(button)

Swift 2.X

let customView = UIView(frame: CGRectMake(0, 0, 200, 50))
customView.backgroundColor = UIColor.redColor()
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
button.setTitle("Submit", forState: .Normal)
button.addTarget(self, action: #selector(buttonAction), forControlEvents: .TouchUpInside)
customView.addSubview(button)
  1. Add that view in Table Footer View.

Swift 2.X/Swift 3.X/Swift 4.X

myTblView.tableFooterView = customView
  1. you can do action on that button in same class.

Swift 3.X/Swift 4.X

func buttonAction(_ sender: UIButton!) {
    print("Button tapped")
}

Swift 2.X

func buttonAction(sender: UIButton!) {
  print("Button tapped")
}

What you need is just a tableFooterView, you can follow this how to add a footer to a uitableview in storyboard