mimi93 mimi93 - 5 months ago 71
Swift Question

Add Footer View In UITableView

This is actually a tableview and tableview cell, and i wanted to add a Submit button after the end of the tableview cell, but how do i do it?
I tried to do it at the storyboard add the button manually, but its not working, the button is not showing. Is there any other way to do it? I wanted to do like the screenshot below.

tableviewcell img

Answer

make one custom view with button,

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)

Add that view in Table Footer View.

myTblView.tableFooterView = customView

you can do action on that button in same class.

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