iOS开发---通过坐标位置获取对应的UITableViewCell

来源:互联网 发布:本地windows调试器 编辑:程序博客网 时间:2024/05/17 04:28
项目上有个场景,自定义一个tableView上显示几个label,label上的信息都是网络获取到的。每个不同的cell上有个相同的button,现在要实现点击button获取该cell上对应的label上的zhi。不要给我说什么给button设tag,tag值已经设置成其他用处了。

现在介绍一种方法,通过屏幕坐标来获取对应的cell。

-(void)pressConvert:(UIButton *)sender event:(id)event{    NSSet *touches = [event allTouches];    UITouch *touch = [touches anyObject];    CGPoint currentTouchPosition = [touch locationInView:_tableView];    NSIndexPath *indexPath = [_tableView indexPathForRowAtPoint:currentTouchPosition];    ConvertGoodsCell *cell = [_tableView cellForRowAtIndexPath:indexPath];//自定义的tableViewCell}
原创粉丝点击