我如何为ios中tableView中单个单元格中的多个按钮设置标签值 [英] how can i set the Tag value For multiple buttons in a single Cell in tableView in ios

查看:23
本文介绍了我如何为ios中tableView中单个单元格中的多个按钮设置标签值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我在 TableView 中有 5 行,每个单元格有四个按钮,我有 20 个按钮,我的要求是我想为每个按钮设置标签值,例如

in my project i have 5 row in a TableView each cell having four button totally i have 20 buttons for this my requirement is i want set tag value for Each buttons like

in First Cell -- 1 for btn1, 2 for btn2, 3 for btn3, 4 for btn4
   Second Cell-- 5 for btn5, 6 for btn6, 7 for btn7, 8 for btn8

像所有五个单元格一样,我需要像这样设置一个标签值

like all Five Cells i need set a tag Value like this

注意:当我滚动 TableView 时,它不会改变标签值

我已经在 cellForRowAtIndexPath 委托方法中设置了这样的标签值

i have set the tag value like this inside the cellForRowAtIndexPath Delegate Method

UIButton *btnLeftW,*btnLeft,*btnRight,*btnRightW;

btnLeftW=(UIButton*)[cell viewWithTag:90];
btnLeft=(UIButton*)[cell viewWithTag:91];
btnRight=(UIButton*)[cell viewWithTag:92];
btnRightW=(UIButton*)[cell viewWithTag:93];

 btnLeftW.tag=indexPath.row;
 btnLeft.tag=indexPath.row;
 btnRight.tag=indexPath.row;
    btnRightW.tag=indexPath.row;

它只给

0,0,0,0
 1,1,1,1
 2,2,2,2
 3,3,3,3 
 4,4,4,4

推荐答案

试试这个

btnLeftW.tag  = indexPath.row*4 + 1;
btnLeft.tag   = indexPath.row*4 + 2;
btnRight.tag  = indexPath.row*4 + 3;
btnRightW.tag = indexPath.row*4 + 4;

这篇关于我如何为ios中tableView中单个单元格中的多个按钮设置标签值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆