Rene Weteling
Rene Weteling

Reputation: 524

UITableView header doesn't listen to scroll

I have a simple UITable and i want a little image before the table starts, so i use a tableheader so far so good, this works quite nicely

self.table.tableHeaderView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:img]];

only the weird thing is when i try to scroll on a table view row the table scrolls but when i try to scroll on the header nothing happens, its like the scroll listener isnt listening to to the scroll event on the header.

Just to be clear the header does scroll when you scroll the table as one piece ( and that is the desired behaviour )

Im googleling like crazy but kant seem to find the answer, thanks!!

some extra code

- (void)viewDidLoad
{

[super viewDidLoad];
// set the table header
self.table.tableHeaderView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header"]];

// add empty footer view to hide empty cells
self.table.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];



// set title
self.navigationItem.title = [self.catData objectForKey:@"titlePage"] ? [self.catData objectForKey:@"titlePage"] : [self.catData objectForKey:@"title"];



}

Upvotes: 1

Views: 803

Answers (3)

Musadhikh Muhammed K
Musadhikh Muhammed K

Reputation: 415

Use Grouped Tableview. then you can scroll your table view.

Upvotes: 1

Hussain Shabbir
Hussain Shabbir

Reputation: 15035

You need to implement this below method:--

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
      CGRect rect = self.tableView.tableHeaderView.frame;
      rect.origin.y = MIN(0, self.tableView.contentOffset.y);
      self.tableView.tableHeaderView.frame = rect;
}

Upvotes: 0

streem
streem

Reputation: 9154

Have you tried setting your header view with :

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIImageView alloc] initWithImage:[UIImage imageNamed:img]];
}

Upvotes: 0

Related Questions