10

感觉我在这里有点疯了。我有一个详细视图,其中包含一些独立的UITextFields、一些UITextFieldsin UITAbleViewCells 和一个UITableViewCell用于保存笔记(如果有的话)的单曲。我只希望在编辑模式下可以选择此单元格。当我不处于编辑模式时,我不希望能够选择它。选择单元格(在编辑模式下)将触发一个方法,该方法将启动一个新视图。我知道这很容易,但我在某处遗漏了一些东西。

以下是我正在使用的当前选择方法:

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (!self.editing) {
        NSLog(@"Returning nil, not in edit mode");
        return nil;
    }
    NSLog(@"Cell will be selected, not in edit mode");
    if (indexPath.section == 0) {
        NSLog(@"Comments cell will be selected");
        return indexPath;
    }
    return nil;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (!self.editing) {
        NSLog(@"Not in edit mode. Should not have made it this far.");
        return;
    }

    if (indexPath.section == 0)
        [self pushCommentsView];
    else
        return;
}

我的问题真的是2倍;

1) 即使我不在编辑模式,并且我知道我正在返回nil(由于NSLog消息),我仍然可以选择该行(它闪烁蓝色)。根据我对willSelectRowAtIndexPath方法的理解,这不应该发生。也许我错了?

2)当我进入编辑模式时,我根本无法选择任何东西。该willSelectRowAtIndexPath方法永远不会触发,didSelectRowAtIndexPath. 我在该setEditing方法中唯一要做的就是在编辑时隐藏后退按钮,并分配firstResponder给顶部的 textField 以使键盘弹出。我想也许第一响应者妨碍了点击(这将是愚蠢的),但即使注释掉了,我也无法在编辑期间执行单元格选择。

4

2 回答 2

16

天哪,我是个白痴。我从来没有添加这些行:

self.tableView.allowsSelection = NO; // Keeps cells from being selectable while not editing. No more blue flash.
self.tableView.allowsSelectionDuringEditing = YES; // Allows cells to be selectable during edit mode.

抱歉这个垃圾问题。

于 2010-05-05T18:37:41.280 回答
4

文档说明tableView:willSelectRowAtIndexPath:在编辑模式下不调用。此外,即使您取消选择,也会出现蓝色闪烁。从文档中:

直到用户触摸一行然后抬起手指时才会调用此方法;直到那时该行才被选中,尽管它在触地时突出显示。您可以使用 UITableViewCellSelectionStyleNone 来禁用触摸时单元格突出显示的外观。当表格的编辑属性设置为YES(即表格视图处于编辑模式)时,不会调用此方法。

于 2010-05-05T18:14:43.043 回答