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

  • Home
  • SEARCH
  • 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 6799863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:53:58+00:00 2026-05-26T18:53:58+00:00

I have two tableView sections, sometimes the first section dosen’t have any data in

  • 0

I have two tableView sections, sometimes the first section dosen’t have any data in it so the second one now comes the first.

In my numberOfSectionsInTableView method I’m counting my first array:

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.firstArray.count == 0) {
    numberOfSections = 1;
} else {
    numberOfSections = 2;
}
return self.numberOfSections;

numberOfSections its an int into my header file.

and here’s how I configure my text for cells

switch (indexPath.section) {
    case 0:
    {
        MyClass *inFirstArray = [appDelegate.firstArray objectAtIndex:indexPath.row];
        cell.detailTextLabel.text = inFirstArray.title;
        break;
    }
    case 1:
    {
        Event *inSecondArray = [appDelegate.secondArray objectAtIndex:indexPath.row];
        cell.detailTextLabel.text = inSecondArray.title;
        break;    

    default:
        break;
    }

}

The problem is that if my firstArray count equals to 0, I don’t have any text into my secondArray…

UPDATE

Also have this methods

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{

    //I'm realeasing it into dealloc
    sectionTitles = [[NSMutableArray alloc] init];

    [sectionTitles addObject:@"first ArrayTitle"];
    [sectionTitles addObject:@"second ArrayTitle"];
    NSString *sectionText = [sectionTitles objectAtIndex:section];
    return sectionText;
}

and

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    //Adding a custom background image for table section header
    NSString *title = [times objectAtIndex:section];
    UIView *customView = [ [ [UIView alloc] initWithFrame: CGRectMake(0.0, -5.0, 320.0, 25.0) ] autorelease ];
    [customView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"tableBackground.png"]]];
    UIButton *button = [ [ [ UIButton alloc ] initWithFrame: CGRectMake(-9.0, 5.0, 320, 27.0) ] autorelease ];
    button.tag = section;
    [button setImage:[UIImage imageNamed:@"header_section_background.png" ] forState: UIControlStateNormal ];
    button.highlighted = NO;
    button.adjustsImageWhenHighlighted = NO;
    UILabel *label = [ [ UILabel alloc ] initWithFrame:CGRectMake(15.0, 5.0, 45, 22.0) ];
    label.alpha = 1.0;
    label.backgroundColor = [UIColor clearColor];

    label.text = title;
    label.textAlignment = UITextAlignmentRight;

    [customView addSubview: button ];
    [customView addSubview:label ];
    [customView sendSubviewToBack:button];

    return customView;
}
  • 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-26T18:53:59+00:00Added an answer on May 26, 2026 at 6:53 pm

    Always return 2 for your numberOfSections. For your numberOfRowsInSection, do the following:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];    
        if (section == 0)
            return [appDelegate.firstArray count];
        else
            return [appDelegate.secondArray count];
    }
    

    So your two sections will always exist, but will have zero rows if there is no data for them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITableView With Two Sections. First section has one row and the
I have one problem with two sections in UITableview grouped style. First section having
In my 'Sectioned' UITableView I have two sections, the first one for Attributes like
My Table has two sections and at the first section I don't have elements
I have a tableview with four sections first section has 7 rows in that
I have a UITableViewController which has two sections. The first section shows a single
I have a grouped tableview with two sections, and I want the cells (in
I have an NSMutableArray in with data (hard coded). I implemented these two TableView
I'm about to load a tableview with two sections. The data will be coming
I have a simple UITableView with two sections. Each section has a header which

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.