When creating each headerView and adding UIButton, you can set its tag to the value of the section and check this tag in the action method for buttons. Sort of...
In your creation:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)]; UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(10, 10, 20, 20); [button setTag:section]; [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; [view addSubview:button]; return view; }
Then in your action method:
- (void)buttonPressed:(UIButton *)sender { int section = sender.tag;
source share