Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
165 views
in Technique[技术] by (71.8m points)

objective c - how can i set the Tag value For multiple buttons in a single Cell in tableView in ios

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

enter image description here

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

Note: When i scroll the TableView it not changing the tag Value

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;

it gives only

0,0,0,0
 1,1,1,1
 2,2,2,2
 3,3,3,3 
 4,4,4,4
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

try this

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...