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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:27:33+00:00 2026-06-04T19:27:33+00:00

Previously, I had a large-ish dataset (~530 records) being displayed in a tableview. The

  • 0

Previously, I had a large-ish dataset (~530 records) being displayed in a tableview. The data was held in an array of dictionaries with two keys, ID and name. Previously, I tapped a cell, it added a check mark, and it sent the cell row number to a ‘selectedArray’. As I had already alphabetically sorted them (still in one section), the indexPath.row which was stored in the selectedArray corresponded to the dictionaries’ array index, so I could pull data (the ID) from the record.

I decided that I would split this into headers by alphabetical order (which was an absolute pain, I don’t see why it’s such a complex process to insert headers into a list of records). But now, as I only used indexPath.row, when I tick the first one, it ticks the first record of each section, and only returns the number 0, so I only get the first record in the whole dataset. Is there a simple way to correct this? Really appreciate any help.

cellForRowAtIndexPath:

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"inviteCell"];

//    cell.accessoryType = UITableViewCellAccessoryCheckmark;

    if ([checkedCells objectForKey:[NSNumber numberWithInt:indexPath.row]] != nil) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else
    {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }


//    NSDictionary *friend = [sortedFriendsArray objectAtIndex:indexPath.row];


    //---get the letter in the current section---
    NSString *alphabet = [nameIndex objectAtIndex:[indexPath section]];
    //---get all states beginning with the letter---
    NSPredicate *predicate =
    [NSPredicate predicateWithFormat:@"SELF.name beginswith[c] %@", alphabet];
    NSArray *states = [sortedFriendsArray filteredArrayUsingPredicate:predicate];
    if ([states count]>0) {
//---extract the relevant state from the states object---

        NSDictionary *friend = [states objectAtIndex:indexPath.row];
        long long fbid = [[friend objectForKey:@"id"]longLongValue];
        NSString *name = [friend objectForKey:@"name"];

        NSString *urlString = [NSString stringWithFormat:@"https://graph.facebook.com/%qi/picture?type=square",fbid];
        NSURL *url = [NSURL URLWithString:urlString];

        UILabel *eventNameLabel = (UILabel *) [cell viewWithTag:1];
        eventNameLabel.text = name;

        UIImageView *eventLogo = (UIImageView*) [cell viewWithTag:2];
        eventLogo.image = [UIImage imageNamed:@"112-group.png"];
        //    eventLogo.image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];;

    }

        return cell;

}

CURRENT didSelectRowAtIndexPath:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    NSNumber *indexNumber = [NSNumber numberWithInt:indexPath.row];
    NSDictionary *friend = [sortedFriendsArray objectAtIndex:indexPath.row];
    long long fbid = [[friend objectForKey:@"id"]longLongValue];
    NSNumber *fbidNum = [NSNumber numberWithLongLong:fbid];

    if ([checkedCells objectForKey:indexNumber] != nil) {
        [checkedCells removeObjectForKey:indexNumber];
        cell.accessoryType = UITableViewCellAccessoryNone;

    }
    else
    {
        [checkedCells setObject:fbidNum forKey:indexNumber];
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }


    NSLog(@"Cell Pressed: %@",indexNumber);
    NSLog(@"FBID: %lld",fbid);
    NSLog(@"Array: %@",checkedCells);
}
  • 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-04T19:27:36+00:00Added an answer on June 4, 2026 at 7:27 pm

    It looks like you’re only saving the checked cells by row, not by section and row. At minimum, don’t you need to be testing the section as well as the row in this block of code?

    if ([checkedCells objectForKey:[NSNumber numberWithInt:indexPath.row]] != nil) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else
    {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    

    It’s late, and I don’t have my Mac handy to try this code, so maybe I’m missing something obvious. I’m not sure what you’re talking about only returning zero … is that indexPath.row?

    EDIT:

    To account for the section in your data array, I’d suggest storing the data as a dictionary of arrays, one dictionary entry keyed by each letter, with the inner array holding all of the entries starting with that letter. It’s a little more complicated to retrieve the data, but it correctly accounts for the section.

    I supposed you could create some kind of an offset to account for the number of entries in each section and then use that to index into a flat array, but that would be a lot harder to maintain, in my view. I think the dictionary of arrays is the way to go.

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

Sidebar

Related Questions

I have two tables: p_group.full_data, which is a large dataset I'm working on (100k
I previously had Passenger 2.2.13 install with NGINX 0.7.65 - I want to install
I previously had a table that is created using hibernate entities. I am using
I previously had a post on this issue that was resolved. However since rebuilding
I have a follow-up question regarding an issue I previously had on SO here
Here is the site in question: http://jayduff.co.uk/ I previously had the images/links on the
I have an application that uses CoreData. I previously had a class named Marker
I have tried everything and this makes absolutely no sense! I previously had Less.js
Previously we had desktop applications but given the fact that accessing the server (either
previously i had custom tableviewcell and was loading from Nib.in that i have specified

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.