在TableView中禁用标题栏的删除/编辑?

huangapple go评论79阅读模式
英文:

Disable Delete/Edit On Header in TableView?

问题

I'm using expanding sections to show/hide tableView rows underneath a header, but would like to exclude the headers from any tableView delete/editing options.

The header is just a custom cell:

if indexPath.row == 0 { //"0" indicates the beginning of each section
let cell = tableView.dequeueReusableCell(withIdentifier: "headerCell", for: indexPath) as! HeaderCell
}

But since the headers and regular cells are all in the same tableView, I don't see a way to exclude the headers from any edits. Is this possible?

Thanks!

英文:

I'm using expanding sections to show/hide tableView rows underneath a header, but would like to exclude the headers from any tableView delete/editing options.

在TableView中禁用标题栏的删除/编辑?

The header is just a custom cell:

   if indexPath.row == 0 { //"0" indicates the beginning of each section
          let cell = tableView.dequeueReusableCell(withIdentifier: "headerCell", for: indexPath) as! HeaderCell
   }

But since the headers and regular cells are all in the same tableView, I don't see a way to exclude the headers from any edits. Is this possible?

Thanks!

答案1

得分: 2

通常的方法是实现 canEditRowAt 方法:

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    return indexPath.row != 0
}
英文:

The usual way is to implement canEditRowAt

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    return indexPath.row != 0
}

huangapple
  • 本文由 发表于 2020年1月3日 22:57:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/59580736.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定