有没有办法在编辑UITableView时隐藏" - "(删除)按钮

iPh*_*Dev 95 iphone cocoa uitableview ios

在我的iphone应用程序中,我有一个处于编辑模式的UITableView,其中只允许用户对行进行重新排序,不给出删除权限.

那么有什么方法可以隐藏TableView中的" - "红色按钮.请告诉我.

谢谢

小智 257

这是我的完整解决方案,没有缩进(0left align)的单元格!

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleNone; 
}

- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}


- (BOOL)tableView:(UITableView *)tableview canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
Run Code Online (Sandbox Code Playgroud)


小智 38

Swift 3相当于只接受所需函数的接受答案:

func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
    return false
}

func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
    return .none
}
Run Code Online (Sandbox Code Playgroud)