Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding iOS UITableView HeaderView (not section header)

I want to add a table header (not section headers) like in the contacts app for example: enter image description here

exactly like that - a label beside an image above of the table.

I want the all view be scrollable so I can't place those outside of the table.

How can I do that?

like image 655
AMM Avatar asked Mar 26 '11 11:03

AMM


People also ask

How do I scroll the header along with UITableView?

If you have a single header in the table then you can use tableHeaderView as below: tableView. tableHeaderView = Header; Or if you have multiple header in table than you need to use Group table instead of plain table.

How can I make the Footerview always stay at the bottom in Uitableviewcontroller?

If you need to make the footer view fixed at the bottom then you can not use a TableViewController . You will have to use UIViewController , put your tableView as a subview. Put the footer also as another subview and its done.


1 Answers

UITableView has a tableHeaderView property. Set that to whatever view you want up there.

Use a new UIView as a container, add a text label and an image view to that new UIView, then set tableHeaderView to the new view.

For example, in a UITableViewController:

-(void)viewDidLoad {      // ...      UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];      UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];      [headerView addSubview:imageView];      UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];      [headerView addSubview:labelView];      self.tableView.tableHeaderView = headerView;      [imageView release];      [labelView release];      [headerView release];      // ... }  
like image 160
peterjb Avatar answered Oct 30 '22 14:10

peterjb