美文网首页iOS技能收集iOS Blog
根据点击位置获取UITableView当前行

根据点击位置获取UITableView当前行

作者: _浅墨_ | 来源:发表于2016-01-30 16:26 被阅读326次
        UIButton * bgBtn = [[UIButton alloc] initWithFrame:cell.mealImageView.frame];
        [cell addSubview:bgBtn];
        [bgBtn addTarget:self action:@selector(mealImageSingleTap: event:) forControlEvents:UIControlEventTouchUpInside];
    
    -(void)mealImageSingleTap:(id)sender event:(id)event {
        
        if( event == nil) return ;
        NSSet *touches = [event allTouches];
        if( touches == nil ) return ;
        UITouch *touch = [touches anyObject];
        if( touch == nil ) return ;
        CGPoint currentTouchPosition = [touch locationInView:self.myTableView];
        NSIndexPath *indexPath = [self.myTableView indexPathForRowAtPoint: currentTouchPosition];
        NSInteger index = indexPath.row;
        NSInteger section = indexPath.section;
        NSString * keyStr = [[self.dataDic allKeys] objectAtIndex:section];
        NSArray * mealArr = [self.dataDic objectForKey:keyStr];
        VASMealInfo * mealInf = [mealArr objectAtIndex:index];
       
    }
    

    相关文章

      网友评论

        本文标题:根据点击位置获取UITableView当前行

        本文链接:https://www.haomeiwen.com/subject/uaajkttx.html