首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从tableViewCell发件人返回错误的UIButton

从tableViewCell发件人返回错误的UIButton
EN

Stack Overflow用户
提问于 2015-04-14 14:57:38
回答 1查看 37关注 0票数 0

对于ios 7和大部分,返回的单元格总是第一个单元,即indexpath.row =0。尽管我考虑的是单元格内的滚动视图和额外的.superview。

代码语言:javascript
复制
- (UITableViewCell *)getCellforButton:(UIButton *)sender
{
    UITableViewCell *cell;

    //Check for iOS version and get the cell accordingly
    NSArray *versionComponenets = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];

    if ([[versionComponenets objectAtIndex:0] intValue] >= 7)
    {
        // iOS-7 code[current] or greater
        //Additional superview call to account for new scrollview inside of cells
        cell = (UITableViewCell *)sender.superview.superview.superview;
    }
    else
    {
        // iOS-6 code
        cell = (UITableViewCell *)sender.superview.superview;
    }

    return cell;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-14 15:04:15

使用UIView's convertPoint:toView method获取UITableViewCell

代码语言:javascript
复制
-(UITableViewCell *)getCellforButton:(UIButton *)sender
{
    CGPoint btnPosition = [sender convertPoint:CGPointZero toView:yourTableViewHere];
    NSLog(@"btnPositionn : %@",NSStringFromCGPoint(btnPosition));
    NSIndexPath *curIndexPath = [yourTableViewHere indexPathForRowAtPoint:btnPosition];
    id cell = [yourTableViewHere cellForRowAtIndexPath:curIndexPath];
    if (cell)
    {
        UITableViewCell *curCell = cell;
        return curCell;
    }
    else
        return nil
 }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29630707

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档