문제

I am currently creating a UITableView with expandable/collapsable sections.

I get data from the Internet in JSON format, storing it in arrays just like this :

{Section 1 {s1 data 1, s1 data 2, ... }, Section 2 {s2 data 1, s2 data 2, and so on}}

Sections can be alphabetical letters, year number or whatever.

I create my table view headers like this :

GTHeaderView *header = [GTHeaderView headerViewWithTitle:[NSString stringWithFormat:@"%@", myArray.SectionValue]];
[header.button addTarget:self action:@selector(toggleSection) forControlEvents:UIControlEventTouchUpInside];

This is fine, but in my "toggleSection" method, I can't find a way to know witch section have been touched to be collapsed/expanded.

I know I can't send parameters in selector... so what solution do you think would fit my needs ?

Thanks in advance !

도움이 되었습니까?

해결책

You can write your toggleSection method as:

- (void)toggleSection:(id)sender
{
   // send the sender object a message to find out the section number here...
}

and of course change your addTarget line to specify that toggleSection method now has one parameter:

[header.button addTarget:self action:@selector(toggleSection:) forControlEvents:UIControlEventTouchUpInside];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top