Есть несколько способов сделать это, но проще всего, вероятно, добавить распознаватель жестов в представление нижнего колонтитула - вам не нужна кнопка, вы можете проверить щелчок где угодно, но ваш дизайн может быть лучшес кнопкой в зависимости от того, что вы включаете в представление нижнего колонтитула.
Вы можете использовать атрибут tag
, чтобы отслеживать раздел, и обработка проста.
Вот быстрыйНапример, где я только что предположил, data1
и data2
представлены в двух разделах
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "tableViewCell", for: indexPath) as UITableViewCell
if indexPath.section == 0
{
cell.textLabel?.text = data1[indexPath.row]
}
else
{
cell.textLabel?.text = data2[indexPath.row]
}
return cell
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let footerView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 30))
footerView.backgroundColor = UIColor.blue
footerView.tag = section
let clickGesture = UITapGestureRecognizer(target: self, action: #selector(self.didClickFooter))
footerView.addGestureRecognizer(clickGesture)
return footerView
}
@objc func didClickFooter(sender : UITapGestureRecognizer) {
// Do what you want here, once you identify the section
if sender.view!.tag == 0
{
data1.append("new data1")
}
else
{
data2.append("new data2")
}
tableView.reloadData()
}