I want to put an info light button in a section header
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 20;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *sectionHeaderView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 20)];
UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
infoButton.frame = CGRectMake(0, 0, 18, 18); // x,y,width,height
infoButton.enabled = YES;
[infoButton addTarget:self action:@selector(infoButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
//Add the subview to the UIView
[sectionHeaderView addSubview:infoButton];
return sectionHeaderView;
}
- (void)infoButtonClicked:(id)sender {
NSLog(@"infoButtonClicked");
}
The button does not respond. I am not quite sure why. It probably is something easy. Any help would be appreciated.
I tried your exact same code (copy and pasted) it into a working UITableView class, and it worked just fine. I was able to tap the button and get the debug output. So your code as shown above is fine, and should work. There must be something else broken in your class.