I have this following code to add a button to my custom header for section.
-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section {
if (tableView == menuListTableView) {
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 40)] autorelease];
UIButton *headerButton = [UIButton buttonWithType:UIButtonTypeCustom];
[headerButton setFrame:CGRectMake(0, 0, tableView.bounds.size.width, 40)];
[headerButton setImage:[UIImage imageNamed:@"Gray_Gradient.png"] forState:UIControlStateSelected];
[headerButton addTarget:nil action:@selector(toggleOpen:) forControlEvents:UIControlEventTouchUpInside];
[headerView addSubview:headerButton];
return headerView;
}
return nil;
}
Why is my button not added to the custom header view?? The sub view array of the headerview seems to be nil when checked in the debugging mode.
Oh I got the answer myself!!! I looked at the button code.. and the control state was set to UIControlStateSelected. instead of UIControlStateNormal. Its so ignorant of me. Sorry guys for the bothering!!