觉得我要去这里有点嚼头。我有几个独立的UITextField
秒,在UITAbleViewCell
个几UITextFields
,和一个单一的UITableViewCell
将被用来保存笔记,如果有任何一个细节视图。当我处于编辑模式时,我只想让这个单元格可选。当我不在编辑模式下时,我不想选择它。选择单元格(处于编辑模式时)将激发一个将启动新视图的方法。我知道这很容易,但我在某处丢失了某些东西。正确设置willSelectRowAtIndexPath和didSelectRowAtIndexPath方法来发送小区选择
下面是我使用的是当前的选择方法:
-(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
顶端文本框来获取键盘弹出。我想也许第一个响应者正在阻碍点击(这将是愚蠢的),但即使有这个评论,我不能在编辑过程中执行单元格选择。
在Xcode 4.2/iOS5中,这些可以在Interface Builder的TableView中设置。 – 2011-11-17 01:42:39
通过在故事板/界面生成器的“选择”选项中选择“Single Selection”来解决它。谢谢! – 2012-06-09 10:01:48