swift - 如何始终将第一个单元格保持在第一个位置

标签 swift uitableview

如何始终将第一个单元格保持在第一个位置,以便在需要对其他单元格重新排序时,第一个单元格无法移动。

最佳答案

试试这个。第一行的编辑将被禁用,而其他行的编辑将被启用。

//快速代码

    func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        if indexPath.row == 0 {
           return false
        }
        return true
    }

//Objective-C代码

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:   (NSIndexPath *)indexPath {
     if (indexPath.row == 0) {
      return true;
     }
     return false;
}

关于swift - 如何始终将第一个单元格保持在第一个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36050374/

相关文章:

ios - 使用破坏性样式和 UIAlertAction 删除按钮

ios - 编辑 Storyboard时 Xcode 7.x 崩溃

arrays - 将 uiTableView 中的选定字符串从 Array 传递到新 ViewController 中的 uiLabel

ios - TableViewCell 颜色问题

ios - 更改表格宽度时,Swift Tableview 会向上移动

swift - 如何使用 SwiftUI 制作单选列表

ios - WebView 未加载 Xcode 9 模拟器中的特定 URL

swift - 如何从字典中制作 Decodable 对象?

swift - XCode:我无法设置 tableView 的委托(delegate)(IB 或以编程方式)

ios - 未从 UITableViewCell 调用委托(delegate)方法