所以,我添加了一个 UITableViewController
和 UITableViewCell
变成 UIViewController
而cellForRowAtIndexPath
委托(delegate)方法有效,didSelectRowAtIndexPath
才不是。有没有人有任何想法?
UITableView
的代表设置为 UIViewController
. UITap...
在我的 [self view]
阻止了didSelectRow...
.我不知道为什么点击会阻止委托(delegate)方法,我也不知道如何让点击和表格同时工作。 我已将日志记录添加到两种委托(delegate)方法中,而一个输出,另一个没有。
View Controller .h
#import "...TableViewCell.h"
...
UITableViewDataSource,
UITableViewDelegate
...
View Controller .m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"cellForRowAtIndexPath");
...
return Cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"didSelectRowAtIndexPath");
}
...TableViewCell.h(内容不重要)
...TableViewCell.m(内容不重要)
最佳答案
我在 another StackOverflow question 上找到了答案.
我有一个 UITapGestureRecognizer
添加到 [self view]
我注释掉了,然后委托(delegate)方法起作用了。
谁能告诉我为什么这有效,以及如何获得 UITapGestureRecognizer
在与 UITableView
相同的屏幕上工作?
// Hide keyboard when user taps outside of it
UITapGestureRecognizer *tapGestureRecognizer =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(hideKeyboardOnTap)];
//[[self view] addGestureRecognizer:tapGestureRecognizer];
UITapeGestureRecognizer
的错字至UITapGestureRecognizer
关于ios - didSelectRowAtIndexPath 不会在 ViewController 中触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19084849/