我有一个包含多个单元格的UItablevIEw.在每个单元格上,我根据一些数组计数动态添加按钮.所以,当我点击一个按钮时,我就可以获得按钮的标签值.但是如何获取该单元格的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; } }解决方法@H_419_18@ 我已经尝试了最大的给定答案,但在我和我通常用于最广义和理想的方式如下:
CGPoint buttonposition = [sender convertPoint:CGPointZero toVIEw:self.tableVIEw]; NSIndexPath *indexPath = [self.tableVIEw indexPathForRowAtPoint:buttonposition];总结
以上是内存溢出为你收集整理的ios – 如何在UITableViewCell中获取UIButton的indexPath?全部内容,希望文章能够帮你解决ios – 如何在UITableViewCell中获取UIButton的indexPath?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)