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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:40:26+00:00 2026-05-16T08:40:26+00:00

Got a weird problem with my NSMutableArray and UITableView. It’s got 4 items in

  • 0

Got a weird problem with my NSMutableArray and UITableView.

It’s got 4 items in the array, the table shows 4 rows but each rows only contains the first array item, rather than row 1 showing array item 1, row 2 showing item 2, etc…

Here’s my code:

My Mutable Array
//in .h

NSMutableArray *tableRows;

//in .m

tableRows = [[NSMutableArray arrayWithObjects:@"For Business, For Pleasure",
                  @"A Great Decision",
                  @"Air Charter Your Honeymoon",
                  @"Time Flies", nil] retain];

My table data source and delegate has

-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    return (NSInteger)[tableRows count];
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID = @"CELL_AIR";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if(cell == nil) {
        cell = [self makeTableCell:cellID identifier:indexPath];
    }
    return cell;
}

-(UITableViewCell *)makeTableCell:(NSString *)identifier identifier:(NSIndexPath *)indexPath {
    //frames
    CGRect cellFrame = CGRectMake(0, 10, 320, 50);
    CGRect lbl1Frame = CGRectMake(10, 0, 320, 25);
    CGRect lbl2Frame = CGRectMake(10, 20, 320, 20);


    UITableViewCell *cell = [[UITableViewCell alloc] initWithFrame:cellFrame reuseIdentifier:identifier];

    UILabel *lbl1 = [[UILabel alloc] initWithFrame:lbl1Frame];
    lbl1.tag=1;
    lbl1.font = [UIFont systemFontOfSize:19];
    lbl1.text = [tableRows  objectAtIndex:indexPath.row];


    UILabel *lbl2 = [[UILabel alloc] initWithFrame:lbl2Frame];
    lbl2.tag=2;
    lbl2.text = @"Tap to read more...";
    lbl2.font = [UIFont systemFontOfSize:12];

    [cell.contentView addSubview:lbl1];
    [cell.contentView addSubview:lbl2];

    return cell;
}

-(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
    return 1;
}

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

Any help would be great appreciated!

Thanks

C

  • 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-16T08:40:27+00:00Added an answer on May 16, 2026 at 8:40 am

    This causes the bug:

    -(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
        return 1;
    }
    

    You have only 1 row for each section. Therefore, for every section, the index path starts at 0 again then you only get the first item in array

    I think the best way to do should be:

    -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
        return 1;
    }
    
    -(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
        return (NSInteger)[tableRows count];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got weird problem. I'm trying to write simple game in C++, but I
I got a weird problem with certificate request that I submit successfully, but when
I'm trying to build a Debian package, but I've got this weird pseudo-directory problem.
I got a weird problem of MySQL index. I have a table views_video :
I got a weird problem. I thought this would cost me few minutes, but
I got a weird problem. I have a program that (does many things but
Today I got a very weird problem which I was able to solve, but
i got a weird problem regarding egrep and pipe I tried to filter a
I've got a weird problem: both my if and else statements are executing. Here's
I've got a weird problem and it's most obviously due to my new status

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.