Monkey original, reprinted. Reprinted Please note: Reprinted from cocos2d Development Network --cocos2dev.com, thank you!
Original address: http://www.cocos2dev.com /? P = 265
XIB is a good thing, but sometimes when I draw a cell, I will set a tag for the control in it to get the child control of each cell in cellforrowatindexpath, if the child control has a uibutton, after you set targeta for it, there is no way to tell which cell button is triggered in the response method, because the uibutton tag of all cells is the same.
Since the tag cannot be changed, is there any other way to know the number of cells in its parent container? Knowing the number of rows does not know which cell is triggered by the button. If you have the idea, you cannot do it.
I thought of using the title of the button. It is to assign a value to the status of the button that is not used, and the title is the number of rows in the cell where the button is located. Then obtain the title from the target and convert it to int. The resulting int is the number of rows.
Set title:
Nsstring * cellstr1 = [nsstring stringwithformat: @ "% d", indexpath. Row];
[Btn_attention settitle: cellstr1 forstate: uicontroleventtouchcancel];
Obtain the title and convert it to the number of rows:
Nsstring * cellindex = [Sender titleforstate: uicontroleventtouchcancel];
Int tag = [cellindex intvalue];
This can be achieved.
However, it is generally better to define a cell. Each cell processes the response of its internal control.
How to use it depends on your needs. After all, the code is dead and the idea is live.