Obtain the number of uitableviewcell rows through cell uibutton

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.