The above answer seems good enough for me, however, if you don't want to use tags you could create a method that returns the section of a UITableView
a particular view belongs to, like so:
-(int)sectionNumberForView:(UIView*)view inTableView:(UITableView*)tableView {
int numberOfSections = [tableView numberOfSections];
int i=0;
for(; i < numberOfSections; ++i) {
UIView *headerView = [tableView headerViewForSection:i];
if (headerView == view) {
break;
}
}
return i;
}
Then inside your Target-Action method and assuming the superview of your button is the section header view:
-(void)buttonPressed:(UIButton*)sender {
int section = [self sectionNumberForView:sender.superview inTableView:_yourTableView];
}
Hope this helps!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…