【发布时间】:2011-02-16 01:09:25
【问题描述】:
感觉我在这里有点疯了。我有几个独立的UITextFields、UITAbleViewCells 中的几个UITextFields 和一个单独的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 以使键盘弹出。我想也许第一响应者妨碍了点击(这会很愚蠢),但即使注释掉了,我也无法在编辑期间执行单元格选择。
【问题讨论】:
标签: iphone uitableview didselectrowatindexpath