这是我的代码
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"Add_plus_iCon_iphone_4s"] forState:UIControlStateNormal];
button.frame = CGRectMake(sectionView.frame.size.width-10, 10, 20, 20);
[button addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
[sectionView addSubview:button];
}
- (void)btnAction:(UIButton *)sender
{
int i = [sender.titleLabel.text intValue];
NSNumber *numb;
if(i == 0)
{
numb = [NSNumber numberWithBool:NO];
sender.titleLabel.text = @"1";
[sender setImage:[UIImage imageNamed:@"Add_minus_iCon_iphone_4s"] forState:UIControlStateNormal];
[sender setImage:[UIImage imageNamed:@"Add_plus_iCon_iphone_4s"] forState:UIControlStateHighlighted];
}
else
{
numb = [NSNumber numberWithBool:YES];
sender.titleLabel.text = @"0";
[sender setImage:[UIImage imageNamed:@"Add_plus_iCon_iphone_4s"] forState:UIControlStateNormal];
[sender setImage:[UIImage imageNamed:@"Add_minus_iCon_iphone_4s"] forState:UIControlStateHighlighted];
}
}