【发布时间】:2012-02-15 16:25:17
【问题描述】:
我有一个UITableView 作为我的UIScrollVIew 的子视图,这是我的MainViewController 控制的主视图。
在 MainViewController.h 中
@interface MainViewController : UIViewController <UIGestureRecognizerDelegate, UITableViewDelegate, UITableViewDataSource>
// other stuff here...
@property (weak, nonatomic) IBOutlet UITableView *myTableView;
在 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 没有被调用,因为我在方法本身和其中的代码行上都设置了断点,并且两者都没有被调用。我也知道数据源工作正常,因为我有其他函数可以在运行时修改单元格并且它们工作得很好。我正在使用将 iOS 5.0 设置为开发目标的最新 Xcode。我已经搜索并搜索了答案。有人有什么想法吗?
编辑:
我找到了答案。我为 myTableView 的 superView 设置了 UITapGestureRecognizer。这覆盖了选择调用。感谢任何建议这可能是它的人。您的答案在我标记为正确之前已被删除。
编辑 2:
很多人都在评论这件事,所以我想分享一下。如果您遇到此问题,只需将 myGestureRecognizer.cancelsTouchInView 设置为 false 即可,一切正常。
【问题讨论】:
-
你实现
tableView:willSelectRowAtIndexPath:了吗?也许它返回 nil 从而阻止didSelectRowAtIndexPath:调用? -
感谢您返回解决方案。我认为将编辑作为答案可能会更好。
-
我会,但我在提出问题后至少 8 小时内无法回答自己的问题。
-
我担心其他事件正在吞噬回调过程。这证实并能够修复。谢谢!
标签: iphone ios uitableview didselectrowatindexpath