ios - UIScrollView 后面的 UITableView

标签 ios objective-c uitableview uiscrollview didselectrowatindexpath

根据我的需要,我在 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/

相关文章:

ios - heightForRowAtIndexPath 设置错误行的高度

iOS Swift UI 测试点击警报按钮

ios - RTSP/RTMP 视频流客户端 iOS

ios - 如何使用 Stripe 和 Swift 获取卡片品牌

ios - 将 OneSignal PlayerID 附加到 iOS Webview URL

iphone - 如何解决这个错误? "property with ' 保留(或强 )' attribute must be of object type"

ios - NSRangeException - 索引 (2008) 超出范围 (1)

ios - 删除 UILabel 填充

objective-c - 标签栏中的自定义 View 在 iOS6 中不再起作用

ios - 如何使 tableHeaderView 与 UITableView 一起弹跳