Добавить несколько нижних колонтитулов в UITableView - PullRequest
0 голосов
/ 19 февраля 2019

Я хочу иметь два нижних колонтитула в моем 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, но у меня все равно не получилось.

Ответы [ 2 ]

0 голосов
/ 19 февраля 2019

Согласно сообщению Sh_Khan, вы можете создать нижний колонтитул в viewForHeaderInSection, например:

override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    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)
    customView.addSubview(button)

    let button2 = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
    button2.setTitle("Submit", for: .normal)
    customView.addSubview(button2)

    return customView
}

Но создание Xib и добавление его в viewForHeaderInSection более полезно

0 голосов
/ 19 февраля 2019

Это

tableView.tableFooterView = customView2

с переопределением первого

tableView.tableFooterView = customView

Вам необходимо сделать 1 представление, которое содержит оба (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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...