May 25
Here is an easy way to create headers and footers for iPhone Table Views.
- In your Xcode project right-click on the Resources folder
- Select: Add / New File … / iPhone OS / User Interfaces / View XIB / [Next]
- Call it HeaderView.xib and click Finish
- GIve the View a unique background color and set the height to 44
- Repeat for FooterView.xib
- Save both files
In your UITableViewController class modify viewDidLoad to contain the following (the editing = YES line is optional – just showing you how to display those cool delete widgets):
- (void)viewDidLoad { self.tableView.editing = YES; // Enable delete buttons. UIView *hView = [[[NSBundle mainBundle] loadNibNamed:@"HeaderView" owner:self options:nil] objectAtIndex:0]; self.tableView.tableHeaderView = hView; UIView *fView = [[[NSBundle mainBundle] loadNibNamed:@"FooterView" owner:self options:nil] objectAtIndex:0]; self.tableView.tableFooterView = fView; }
As far as I can tell you can’t lock the header and footer in place. That will require a custom table view.
Tags: footers, headers, tables, UITableViewController, views