Dancer
Dancer

Reputation: 17701

UITableViewCell - No Section Header only for first cell

Is it possible to hide/remove the first tableviewHeader only?

basically I want to show a custom cell which will be designed as an offer - I dont want this to have a header - could I add this logic to my heightForHeaderInSection method -

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

    return 40;
}

Upvotes: 1

Views: 588

Answers (4)

ihammys
ihammys

Reputation: 812

Try the following way for your table view's headers

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0)
            return 1.0f;
    return 40.0f;
}

- (NSString*) tableView:(UITableView *) tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return nil;
    } else {
        // return some string here ...
    }
}

- (void) viewDidLoad
{
    [super viewDidLoad];

     self.tableView.contentInset = UIEdgeInsetsMake(-1.0f, 0.0f, 0.0f, 0.0);
}

Upvotes: 0

Greg
Greg

Reputation: 25459

Yes you should do:

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0)
        return 0.0;
    else
        return 40;
}

And also if you use titleForHeaderInSection: you should return nil when section = 0.

Upvotes: 1

Bhumeshwer katre
Bhumeshwer katre

Reputation: 4671

Try this:

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

    if(section == 0)
    {
       return 0;
     }
    return 40;
}

Upvotes: 0

Midhun MP
Midhun MP

Reputation: 107231

Check with this:

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == 0)
    {
         return 0;
    }
    return 40;
}

Or you can implement viewForHeaderInSection

 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
 {
     if(section == 0)
     {
         return nil
     }
     //else return header view
 }

Upvotes: 5

Related Questions