Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 512729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:20:59+00:00 2026-05-13T07:20:59+00:00

Here is the deal: I have a UITableView with 2 sections, and I want

  • 0

Here is the deal: I have a UITableView with 2 sections, and I want to display a “no data” cell when the first section is empty, so that the 2 section headers are not stuck together (cause it looks weird).

It works great (even though I had trouble making it work at first, see this thread). I’m using viewForFooterInSection :

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

if(section == 0)
{
        if([firstSectionArray count] == 0)
                return 40;
        else 
                return 0;
}

return 0;

}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{

    if(section == 0)
    {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(200, 10, 50, 44)];
        label.backgroundColor = [UIColor clearColor];
        label.textColor = [UIColor colorWithWhite:0.6 alpha:1.0];
        label.textAlignment = UITextAlignmentCenter;
        label.lineBreakMode = UILineBreakModeWordWrap; 
        label.numberOfLines = 0;
        label.text = @"No row";
        return [label autorelease];
    }

    return nil;
}

But the background color turns plain white when I display the section footer view. See image:

alt text http://img683.yfrog.com/img683/9480/uitableviewproblem.png

I like it better when the background is filled with empty cells. Does anyone have any idea how to do that? Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:20:59+00:00Added an answer on May 13, 2026 at 7:20 am

    The background is filled with empty cells when you have no footer. So do not implement a viewForFooterInSection (or titleForFooterInSection) method, and you will get the “empty cells” effect.

    I’d recommend that you return a cell indicating that there are no entries to show, like so:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        if (matches.count>0) {
            // Do your usual thing here
        } else {
            static NSString *cellId = @"noDataCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (cell == nil) {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId] autorelease];
                cell.textLabel.textAlignment = UITextAlignmentCenter;
                cell.textLabel.textColor = [UIColor grayColor];
            }
            cell.textLabel.text = @"Aucun match";
            return cell;
        }
    }
    

    And of course, you would have to tell UIKit that you always have at least one cell in your section… I’ve added the isDeletingRow case that seems to trouble you (in comment).

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        if (section==0) return matches.count>0 ? matches.count : (isDeletingRow ? 0 : 1);
        // Set 'isDeletingRow' to YES when a delete is being committed to the table, in that case we let UIKit know that we indeed took care of the delete...
        // And cover the other sections too...
    }
    

    When you are committing the edits, you need to set isDeletingRow for numberOfRowsInSection to return a satisfactory value…

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
        if (editingStyle == UITableViewCellEditingStyleDelete) {
            isDeletingRow = YES;
            // Your current code when a row is deleted here...
            isDeletingRow = NO;
            if (matches.count==0) [self.tableView performSelector:@selector(reloadData) withObject:nil afterDelay:0.5];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITableView that looks like this: In the first cell I display
so here is the deal: I have a label (NSTextField) that I want to
here's the deal, I have to make a game that resembles PacMan, with a
Here's the deal I have HTML code like this <form action=/test.php> First name: <input
first time asking. Here's the deal: I have a helper class (at least now
Ok, so here's the deal: Currently we have a page that calls a popup
So here is the deal. I have a div I want to show the
So here's the deal I'm working on a project that requires me to have
So here's the deal I'm working on a project that requires me to have
OK, here is the deal. I have 3 queries putting data in different tables.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.