Reputation: 15
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.
Upvotes: 0
Views: 830
Reputation: 100503
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
Upvotes: 1