感觉我在这里有点疯了。我有一个详细视图,其中包含一些独立的UITextField
s、一些UITextFields
in UITAbleViewCell
s 和一个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 以使键盘弹出。我想也许第一响应者妨碍了点击(这将是愚蠢的),但即使注释掉了,我也无法在编辑期间执行单元格选择。