根据我的需要,我在 UISCrollView 下直接添加了一个 UITableView :
--- 主 UIView
-------- UITableView
-------- UIScrollView
因此,当我滚动我的 ScrollView 时,我更改了我的表格 View 的内容偏移量。它工作得很好。 但是当我试图选择一个单元格时,我无法捕获委托(delegate)方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
有什么特别的事情要做吗?我尝试子类化 UIScrollView 并实现:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
它可以工作,但我无法滚动我的 UIScrollView ...
最佳答案
试试这个,
-(void)handleSingleTap:(UILongPressGestureRecognizer *)gestureRecognizer{
CGPoint p = [gestureRecognizer locationInView:myScroll];
NSIndexPath *indexPath = [myTable indexPathForRowAtPoint:p];
[myTable selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
[self tableView:myTable didSelectRowAtIndexPath:indexPath];
}
你必须使用 UITapGestureRecognizer...
UITapGestureRecognizer *tpgr = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleSingleTap:)];
tpgr.numberOfTapsRequired = 1;
[myScroll addGestureRecognizer:tpgr];
关于ios - UIScrollView 后面的 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14703476/