英文:
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.
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
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论