在UITableView中重新排序控件

21 iphone uitableview

我正在开发一个游戏,其中我使用的UITableView是具有自定义单元格(UItableViewCell子类)的游戏.

在编辑模式下: 只显示重新排序控件UITableView.

现在我正在获取删除和重新排序控件.

如何在编辑时只进行重新排序控制?

Mou*_*usa 62

我知道这个答案可能会迟到,但我只是为了那些仍然需要它的人.只需实现以下方法:

- (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;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{

}
Run Code Online (Sandbox Code Playgroud)


oxi*_*gen 1

 tableView.showsReorderControl = YES; // to show reordering control
Run Code Online (Sandbox Code Playgroud)

要解除删除控件,请在 UITableViewDelegate 中添加

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleNone;
}
Run Code Online (Sandbox Code Playgroud)