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 8942639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:33:51+00:00 2026-06-15T11:33:51+00:00

This is my code to populate UITableView, very very simple: file .h @interface ViewController:

  • 0

This is my code to populate UITableView, very very simple:

file .h

@interface ViewController: UIViewController {
    IBOutlet UITableView *table;
    NSMutableArray *array1;
    NSString *string1
}

file .m

- (void)viewDidLoad
{
    [super viewDidLoad];
    array1 = [[NSMutableArray alloc] initWithObjects: @"1", @"2", @"3", @"4", nil];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return array1.count; // <------- here there is the problem with iOS 5.1, also [array1 count]
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 20;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:
                 UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
    }

    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.detailTextLabel.backgroundColor = [UIColor clearColor];

    cell.textLabel.text = [NSString stringWithFormat:@" %@",[array1 objectAtIndex:indexPath.row]];
    cell.textLabel.font = [UIFont systemFontOfSize:13];
    cell.textLabel.textColor = [UIColor blackColor];

    return cell;
}

Well, in iOS 6 (simulator and real device) its all right, UITableView loads and shows all rows of array1 objects; in iOS 5.1 (simulator and real device) it doesnt crash but UITableView is empty, no rows showed (Header and Footer are attached), and I’have noticed this could be a problem with the numberOfRowsInSection: array1.count method, I think in iOS 5.1 it doesnt recognize the right number of rows. Please, what’s the best way to write a code compatible with iOS 5.1 and iOS6?

  • 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-06-15T11:33:52+00:00Added an answer on June 15, 2026 at 11:33 am

    After populating the array1 do

    [self.tableView reloadData];
    

    Since I think the data is not available when the tableview is loaded. And this could be different between iOS 5 and 6.

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

Sidebar

Related Questions

I have this code below to populate my UITableView on the fly. I have
In a branch of my code, I previously used this NSMutableArray *array1 = [[NSMutableArray
I am using this code in a loop to populate an NSMutable Array of
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
I'm using the following code to populate a UITableViewController - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
I have an UITableView and I want to populate it with data from this
this is driving me MAD now.. I have a UItableview. Based on an NSMutableArray,
This seems to be a very simple thing, but I don't know how to
I have a class like this: @interface ExerciseLogDetails : UIViewController<UIActionSheetDelegate, UITableViewDelegate, UITableViewDataSource> { where
This code below allows me to find the word error in all my files

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.