I have a UITableViewController and I want to extend the tableHeaderView of that table a bit.
So in viewDidLoad I added the following:
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.frame.size.width, 60.0f)];
Fine, works well – I got my header view.
Now I want to add a Button on top of that view. So I add the following code:
UIButton *someButton = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 20.0f)];
[someButton setTitle:@"Filter" forState:UIControlStateNormal];
[self.tableView.tableHeaderView addSubview:someButton];
But the button don’t appear on the tableHeaderView. When I run the same code with a UILabel instead of a UIButton I can see the label.
Where’s my mistake?
Have a look at this SO question: UIButton – alloc initWithFrame: vs. buttonWithType:
I recommend you use
UIButton *someButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];or something similar to that.