iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 如何在UITableViewCell中获取UIButton的indexPath?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

参见英文答案 > How to know the UITableview row number                                    10个 我有一个包含多个单元格的UITableview.在每个单元格上,我根据一些数组计数动态添加按钮.所以,当我点击一个按钮时,我就可以获得按钮的标签值.但是如何获取该单元格的indexPath? 这是我在-cellForRowAt
参见英文答案 > How to know the UITableview row number                                    10个
我有一个包含多个单元格的UITableview.在每个单元格上,我根据一些数组计数动态添加按钮.所以,当我点击一个按钮时,我就可以获得按钮的标签值.但是如何@L_262_6@该单元格的indexPath?

这是我在-cellForRowATindexPath中的代码

UIView *view=(UIView*)[cell.contentView viewWithTag:indexPath.row+444];

   UIImageView *img=(UIImageView*)[cell.contentView viewWithTag:indexPath.row+999];
   img.image=[UIImage imagenamed:@"BHCS_empty.png"];

   if(Integer!=50)
   {
        NSInteger y_axis=0;
        NSArray *Arr=[tableSubCategoryArr objectATindex:indexPath.row];
        img.image=[UIImage imagenamed:@"BHCS_SELEcted.png"];

        view.Frame= CGRectMake(0,50,281,Integer-50);
        for (int i=0; i<[Arr count]; i++)
        {
            NSLog(@"arr %@",[Arr objectATindex:i]);
            UIButton *Btn=[UIButton buttonWithType: UIButtonTypeCustom];
            Btn.frame=CGRectMake(0,y_axis,44);
            [Btn setImage:[UIImage imagenamed:@"BHCS_panel.png"] forState:UIControlStateNormal];
            [Btn addTarget:self action:@SELEctor(subCategoryBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
            [Btn setTag:i+100];
            [view addSubview:Btn];


            UILabel *nameLbl=[[UILabel alloc]initWithFrame:CGRectMake(20,248,44)];
            nameLbl.text = [[Arr objectATindex:i]objectForKey:@"SubCategoryName"];
            nameLbl.textColor = [UIColor whiteColor];
            nameLbl.BACkgroundColor=[UIColor clearColor];
            panelTableView.separatorColor = [UIColor colorWithPatternImage:[UIImage imagenamed:@"BHCS_panel_div1.png"]];
            nameLbl.font = [UIFont fontWithName:@"Helvetica" size:12.0f];
            [view addSubview:nameLbl];

            y_axis=y_axis+44+1.3f;
        }
    }

解决方法

我已经尝试了最大的给定答案,但在我和我通常用于最广义和理想的方式如下:

CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
 NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];

大佬总结

以上是大佬教程为你收集整理的ios – 如何在UITableViewCell中获取UIButton的indexPath?全部内容,希望文章能够帮你解决ios – 如何在UITableViewCell中获取UIButton的indexPath?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。