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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:42:57+00:00 2026-05-21T16:42:57+00:00

I am trying to get the first five cards in one section and other

  • 0

I am trying to get the first five cards in one section and other five in next section of table view . Actually I have done parsing and unable to get proper cell values. The thing I am getting is combined values for example : in section = birthday cell values are card1, card2 and again card1, card 2 of new year section, and in other section same thing is repeating. What should I do to make grouped i.e card1, card 2 in birthday section and card1, card2 should be in new year section. Here is my code:

 (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
    NSLog(@"section in rv");
}

 (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return [appDelegate.books count];
        NSLog(@".....appDelegate.books count");
}


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

    NSLog(@"cell for index path");
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
      {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
              }
    Book *aBook = [appDelegate.books objectAtIndex:indexPath.row];
    NSLog(@"text for cell...");
    cell.text = aBook.Subcatname;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
    [appDelegate release];
  }
  • 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-21T16:42:58+00:00Added an answer on May 21, 2026 at 4:42 pm

    Take a look at dks1725’s response to set up the correct number of rows per section.

    Also, and more directly in response to your question, in tableView:cellForRowAtIndexPath: for each table row you are always returning a cell with the same content, regardless of what section the cell is in. That’s why you are getting the same content (‘card1’, ‘card2’ and so on) appearing in each section.

    Keep in mind that the indexPath you are receiving in this method has two components: indexPath.rowand indexPath.section. You are ignoring the second of these, and so, for every section, you always return the same cell for a each row.

    You will need to modify tableView:cellForRowAtIndexPath: so that a piece of it will look something like the following:

    if (indexPath.section == 0) {
        //Retrieve the content you want for each row in section 0
        //It will look something like this, but will be different depending on where you stored your content
    
        Book *aBook = [appDelegate.books objectAtIndex:indexPath.row];
        cell.text = birthdayBook.Subcatname;
    }
    if (indexPath.section == 1) {
        //Retrieve the content you want for each row in section 1
        //It will look something like this, but will be different depending on where you stored your content
    
        Book *aBook = [appDelegate.books objectAtIndex:indexPath.row + 5];
        cell.text = newyearsBook.Subcatname;
    }
    ...
    

    The above is edited as per your comments.
    Given your model, you could also do it in fewer lines, as follows:

       - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 2;}
    -(NSString *)tableView:(UITableView *)tblView titleForHeaderInSection:(NSInteger)section {
        NSString *sectionName = nil;
        switch(section)
        {
            case 0:
                sectionName = [NSString stringWithString:@"birthday"];
                break;
            case 1:
                sectionName = [NSString stringWithString:@"new year"];
        }
        return sectionName;
    }
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
       {
           NSInteger count; 
           if(section == 0) 
           { count=5; } 
           else if(section == 1)
           { count=5; }
           return count;
       }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        NSLog(@"cell for index path");
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil)
          {
            cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
             }
        NSLog(@"text for cell...");
        if(indexPath.section == 0)
        {       
          Book *aBook = [appDelegate.books objectAtIndex:indexPath.row];
            cell.text = aBook.Subcatname;
               }
        else if(indexPath.section == 1)
        {
          Book *aBook = [appDelegate.books objectAtIndex:indexPath.row+5*indexPath.section];
           cell.text = aBook.Subcatname;
            }
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return cell;
        [appDelegate release]; 
    
          }
    
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        // Navigation logic -- create and push a new view controller
    
        if(bdvController == nil)
            bdvController = [[BookDetailViewController alloc] initWithNibName:@"BookDetailView" bundle:[NSBundle mainBundle]];
        NSLog(@"pushing to bdv controller");
        if(indexPath.section == 0)
        {       
            Book *aBook = [appDelegate.books objectAtIndex:indexPath.row];
            bdvController.aBook = aBook;
        }
        else if(indexPath.section == 1)
        {
            Book *aBook = [appDelegate.books objectAtIndex:indexPath.row+5*indexPath.section];
        bdvController.aBook = aBook;
        }
            NSLog(@"push to view descrip, id, pic url");
        //bdvController.aBook = aBook;
        NSLog(@"loop");
        [self.navigationController pushViewController:bdvController animated:YES];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get this graphing calculator to work. I have two view controllers,
I am trying get my first simple project in rails to run. I have
I'm trying to get the first day of the next quartal, for example now
I'm trying to get the first article on the page using CSS. I have
I am trying to get the first word in the line that matches the
I am trying to get my first button to update a display number in
Ok I am trying to get the users First Name the form gets their
When trying to get geolocation on iPhone the first time - I declined. Every
I am trying to get the names of all first level directories under given
I am trying to get PhysX working using Ubuntu. First, I downloaded the SDK

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.