6

您好,在表格视图编辑模式下,不会调用 didselectrowatindexpath 函数。这是我的代码。我的代码有什么问题吗?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  {
    if (self.tableView.editing == YES)   {
        NSLog(@"now in editing mode");
    }
    else {
        NSLog(@"now in normal mode");
    }
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated   {
    [super setEditing:editing animated:animated];
    // must be called first according to Apple docs
    [self.tableView setEditing:editing animated:animated];
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath   {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}

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

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

请帮忙。谢谢

4

2 回答 2

19

您必须将此属性设置allowsSelectionDuringEditingUITableView才能TRUE编辑模式下选择行。所以应该是

self.tableView.allowsSelectionDuringEditing=YES;
于 2013-07-15T10:33:08.697 回答
1

我不相信它默认启用,但您必须指定在编辑期间应允许哪些选择,就像非编辑选择一样。根据您的需要使用以下两行之一。

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.tableView setAllowsMultipleSelectionDuringEditing:YES];
    [self.tableView setAllowsSelectionDuringEditing:YES];
}
于 2013-07-15T10:33:28.840 回答