gpt4 book ai didi

ios - 向 UITableView 添加多个页脚

转载 作者:行者123 更新时间:2023-11-29 06:00:13 25 4
gpt4 key购买 nike

我想在我的 UITableView 中有两个页脚。我用它来添加页脚:https://stackoverflow.com/a/38178757/10466651

我尝试在 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

但它只是互相超越。我尝试使用 CGRect y,但对我来说仍然不起作用。

最佳答案

这个

tableView.tableFooterView = customView2

覆盖第一个

tableView.tableFooterView = customView

您需要创建 1 个包含两者的 View ( customView + customView2 ),然后将其指定为页脚

<小时/>
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

关于ios - 向 UITableView 添加多个页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54755805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com