didSelectRowAtIndexPath:未被调用 [英] didSelectRowAtIndexPath: not being called
问题描述
我有 UITableView
作为我的 UIScrollVIew
的子视图,这是我的<$控制的主视图C $ C> MainViewController 。
I have a UITableView
as a subview of my UIScrollVIew
, which is the main view controlled by my MainViewController
.
在MainViewController.h中
In MainViewController.h
@interface MainViewController : UIViewController <UIGestureRecognizerDelegate, UITableViewDelegate, UITableViewDataSource>
// other stuff here...
@property (weak, nonatomic) IBOutlet UITableView *myTableView;
在MainViewController.m中
In MainViewController.m
@synthesize myTableView;
// other stuff here...
- (void)viewDidLoad {
myTableView.delegate = self;
myTableView.datasource = self;
}
// other stuff here...
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath {
[self performSegueWithIdentifier:@"listAttributesSegue" sender:self];
}
我知道 didSelectRowAtIndexPath
没有被调用,因为我已经在方法本身和它内部的代码行上设置了断点,并且都没有被调用。我也知道数据源工作正常,因为我有其他功能可以在运行时修改单元格,并且它们工作正常。我使用最新的Xcode和iOS 5.0设置作为开发目标。我搜索并搜索了一个答案。任何人都有任何想法?
I know that didSelectRowAtIndexPath
is not being called because I have set breakpoints on both the method itself and the line of code inside it, and neither is being called. I also know that the datasource is working correctly because I have other functions which modify the cells at runtime and they are working perfectly fine. I am using the latest Xcode with iOS 5.0 set as the development target. I have searched and searched for an answer. Anyone have any ideas?
编辑:
我找到了答案。我为myTableView的superView设置了 UITapGestureRecognizer
。这超出了选择呼叫。相信任何人都认为可能是这样。在我将其标记为正确之前,您的答案已被删除。
I have found the answer. I had a UITapGestureRecognizer
set for myTableView's superView. This overrode the selection call. Credit to whoever suggested that that might be it. Your answer was deleted before I could mark it correct.
编辑2:
很多人一直在评论此事,所以我虽然会分享它。如果您遇到此问题,只需将 myGestureRecognizer.cancelsTouchInView
设置为 false
,一切正常。
Edit 2:
A lot of people have been commenting about this, so I though I would share it. If you are experiencing this problem, simply set myGestureRecognizer.cancelsTouchInView
to false
and everything should work fine.
推荐答案
我找到了答案。我为myTableView的superView设置了UITapGestureRecognizer。这超出了选择呼叫。相信任何人都认为可能是这样。在我将其标记为正确之前,您的答案已被删除。
I have found the answer. I had a UITapGestureRecognizer set for myTableView's superView. This overrode the selection call. Credit to whoever suggested that that might be it. Your answer was deleted before I could mark it correct.
将 cancelsTouchesInView
属性设置为手势识别器上没有
,允许表视图拦截事件。
Set the cancelsTouchesInView
property to NO
on the gesture recogniser to allow the table view to intercept the event.
这篇关于didSelectRowAtIndexPath:未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!