2

Can someone provide the source code to do that? I set the data source and delegate and tried

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

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //remove the deleted object from your data source.
    }
}

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

but it's not working. I don't want to add UIGestureRecognizer to the cells if possible.

Appreciate if someone gives suggestion.

Thank you very much!

4

1 回答 1

1

确保您的 .h 文件中的控制器正在实现 UITableViewDelegate 协议,并将您的表数据源设置为该控制器。试试这个,让我知道这些函数是否被调用。

例子...

SomeController.h 文件

@interface SomeController : UIViewController <UITableViewDataSource>
....

SomeController.m 文件

....

    myTableView.dataSource = self;

....

-祝你好运!

于 2013-05-23T21:37:18.153 回答