KDeogharkar
KDeogharkar

Reputation: 10959

Give the header only to specified table

I had two UITableView in my project and I am giving custom header to one table using the method:

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if(tableView.tag == 3)
    {
    SectionInfo *array  = [self.sectionInfoArray objectAtIndex:section];
    if (!array.sectionView)
    {
        NSString *title = array.groupdeck.groupTitle;
        array.sectionView = [[SectionView alloc] initWithFrame:CGRectMake(0, 0, tblData.bounds.size.width, 45) WithTitle:title Section:section delegate:self];
    }
    return array.sectionView;
    }
    else{
        return 0;
    }

return 0;
}

It is giving the header to the table with the tag 3 like:

enter image description here

But it is giving the default header to other table also even return 0 else condition like:

enter image description here

What am I missing?

Upvotes: 0

Views: 99

Answers (3)

Anil Kothari
Anil Kothari

Reputation: 7733

With Reference to written in Apple Documentation

 // custom view for header. will be adjusted to default or specified header height
    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section; 

It is displaying the default header which has height of 22 for grouped table and 10 for nongrouped table.

Also if the height of your view which you want to display in UITableView is more than above values then you also have to use the UITableView Delegate method

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

Upvotes: 0

Rushi
Rushi

Reputation: 4500

Try :

otherTable.sectionHeaderHeight = 0.0;

You don't have to do anything else.

Or:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
 { 
      if(tableView.tag == 3)
      {
          //Required height.
      }
      else
      {
          return 0.0; 
      }
 }

Upvotes: 2

blaa
blaa

Reputation: 438

It might be defaulting to the default header because you returned a 0. Try returning nil instead.

From: tableView:viewForHeaderInSection: default value?

Upvotes: 2

Related Questions