在UITableView中重新排序控件

时间:2009-09-01 11:02:27

标签: iphone uitableview

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

在编辑模式中 只应显示UITableView的重新排序控件。

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

如何在编辑时仅重新排序控件?

5 个答案:

答案 0 :(得分: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{

}

答案 1 :(得分:4)

非常感谢它有效吗...... 我写的是

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

     static NSString *CellIdentifier = @"Cell";

     UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];

     if (!cell) {
         cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
     }

     cell.showsReorderControl = YES; // to show reordering control

    return cell;
}

但是我写了你给出的方法

非常感谢

答案 2 :(得分:4)

您应该使用此方法隐藏删除按钮。

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

答案 3 :(得分:1)

 tableView.showsReorderControl = YES; // to show reordering control

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

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

答案 4 :(得分:1)

Swift 5.0

如果您要禁用tableView单元格的所有其他编辑选项(允许您对其重新排序的选项除外),则只需从UITableViewDelegate实现这些方法:

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

// Removes the ability to delete current cell
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
    return UITableViewCellEditingStyle.none
}

func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
    return true
}
相关问题