如何在编辑模式下选择行?

She*_*lam 14 iphone cocoa-touch objective-c uitableview

我有一个可编辑的UITableView.我通过以下方式提交更改:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)

在编辑模式下,我希望用户能够选择一行,这将推送一个新视图.我不知道该怎么做.我怀疑它会在:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)

但是如何确定用户是否处于编辑模式?

更新:编辑模式通过以下方式切换:

self.navigationItem.rightBarButtonItem = self.editButtonItem;
Run Code Online (Sandbox Code Playgroud)

ric*_*son 31

要在编辑期间选择,您需要将allowsSelectionDuringEditing属性设置UITableView为YES.然后它将调用该didSelectRowAtIndexPath消息.您可以在此处找到有关该属性的更多信息:

http://developer.apple.com/iphone/library/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instp/UITableView/allowsSelectionDuringEditing

然后,您可以通过运行以下代码来查看用户是否处于编辑模式:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView.editing == YES) {
        // Table view is editing - run code here
    }
}
Run Code Online (Sandbox Code Playgroud)