0

I want to have two footers in my UITableView. I have used this to add a footer: https://stackoverflow.com/a/38178757/10466651

I tried adding two footers like this in the viewDidLoad:

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)
tableView.tableFooterView = customView

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

But it just goes over eachother. I tried playing with the CGRect y, but still wont work for me.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Trinity
  • 15
  • 7
  • Basically, you want put two buttons into footerview? – Tieda Wei Feb 18 '19 at 21:56
  • I was thinking about two buttons as footer(or 2 footers if possible?) – Trinity Feb 18 '19 at 21:59
  • You can draw a `containerView` first, set it as the `footerView`, then put the two buttons inside – Tieda Wei Feb 18 '19 at 22:02
  • tableView.tableFooterView = customView tableView.tableFooterView = customView2 here the "=" is assignment operator. and you are first assigning customView1 and then assigning customView2. it will not add two tablefooters that way for sure. You will need to create a single footer view (because tableview can take only one) and add your buttons or any other views in that container view and assign it to the tableview – Umair Feb 19 '19 at 03:21

1 Answers1

1

This

tableView.tableFooterView = customView2

with override the first

tableView.tableFooterView = customView

You need to make 1 view that contains both ( customView + customView2 ) , then assign it as the footer


let customView = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 115))
customView.backgroundColor = UIColor.red
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
button.setTitle("Submit 1", for: .normal)
button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
customView.addSubview(button)  
let button2 = UIButton(frame: CGRect(x: 0, y: 65, width: 100, height: 50))
button2.setTitle("Submit 2", for: .normal)
button2.addTarget(self, action: #selector(buttonAction2), for: .touchUpInside)
customView.addSubview(button2)
tableView.tableFooterView = customView
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87