我正在编写一个带有tab视图中的表视图的iOS应用程序。在我的UITableViewController中,我实现了-tableView:didSelectRowAtIndexPath:,但当我在运行时选择一行时,该方法没有被调用。表格视图正在被填充,所以我知道控制器中的其他tableView方法正在被调用。
有没有人知道我到底搞砸了什么才让这一切发生的?
我正在编写一个带有tab视图中的表视图的iOS应用程序。在我的UITableViewController中,我实现了-tableView:didSelectRowAtIndexPath:,但当我在运行时选择一行时,该方法没有被调用。表格视图正在被填充,所以我知道控制器中的其他tableView方法正在被调用。
有没有人知道我到底搞砸了什么才让这一切发生的?
当前回答
确保你实现了tableView:didSelectRowAtIndexPath而不是tableView:didDeSelectRowAtIndexPath
这让我在很多场合!!
其他回答
您必须选择这些选项
但是如果你想让uitableview在点击时不突出显示,那么你应该改变UITableViewCell属性。
选择“选择”的“无”选项,如下所示
我在我的表视图上放了一个UITapGestureRecognizer来消除键盘,这阻止了didSelectRowAtIndexPath:被调用。希望它能帮助到别人。
在我的案例中,解决方案是在下面的函数中将NO更改为YES。
iOS 9 +
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
都是很好的答案,但还有一个需要注意……
(特别是当以编程方式创建UITableView时)
确保tableView可以通过设置[tableView setAllowsSelection:YES]来响应选择;或者删除任何将其设置为NO的行。
在我的情况下,问题是我有一个UITableViewCell子类,我实现了这两个方法: touchesBegan:withEvent: & touchesEnded:withEvent处理一个花哨的触摸动画。 但是我忘记添加[super touchesBegan: touchwithevent:event];方法ad [super touchesEnded: touchwithevent:event];也通知父单元的触摸。
所以将代码更改为以下解决了我的问题:
-(void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{
[super touchesBegan:touches withEvent:event];
//blah blah blah
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesEnded:touches withEvent:event];
//rest of the code
}