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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:02:20+00:00 2026-06-16T02:02:20+00:00

My app has a TableView with a list of blog articles, sorted by day.

  • 0

My app has a TableView with a list of blog articles, sorted by day. When an article’s row is selected, it adds the title of the article into a NSUserDefault NSMutableArray. When the view is refreshed, the app takes the array, uses NSPredicate to sort the array for items in the array that match the title of the article, and if a title matches, it adds a checkmark. The issue is that because I am using NSString it only adds a checkmark to one of the rows…whichever the most recent entry to the NSMutableArray was. Here is my code for cellForRowAtIndexPath:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
NSArray *rowsarray = [defaults objectForKey:@"checkedrows"];

NSPredicate *predicate = [NSPredicate predicateWithFormat: @"SELF contains[cd] %@",  entry.date];

NSArray *filteredArray = [rowsarray filteredArrayUsingPredicate: predicate];
NSString *myString = [filteredArray componentsJoinedByString:@""];

NSLog(@"The array %@", filteredArray);
NSLog(@"The string %@", myString);

if([entry.date isEqualToString:myString])
{
   cell.accessoryType = UITableViewCellAccessoryCheckmark;

}

In the console, MYSTRING gets printed out multiple times, once for each item in the array, but only adds a checkmark to the row for the first returned article title. How can I get it to add checkmarks to every one that is in the array?

UPDATE: I added the logs above to print out the filteredArray and then the string. I found the error, it seems to be taking the first item in the array and formatting it in a way that matches the entry.date, but the 2nd is not. Here is the printout in console.

The array (
    "Day 2: "
)


The string Day 2:


The array (
        (
        "Day 1: "
    )
)



The string (
    "Day 1: "
)

As you can see, the console shows something different for day 1 than day 2. day 2 works, but the other doesn’t. Any suggestions? Oh, also, the original Array before using NSPredicate shows

(
        (
        "Day 1: "
    ),
    "Day 2: "
)

Could it be I need to edit either the predicate or the string in componentsJoinedByString?

Update:

Code for adding values to NSUserDefaults.

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
NSMutableArray *rowsarray2 = [[NSMutableArray alloc] initWithObjects:[defaults objectForKey:@"checkedrows"], nil]; 
[rowsarray2 addObject:entry.date]; 
[defaults setObject:rowsarray2 forKey:@"checkedrows"]; 
[defaults synchronize];
  • 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-16T02:02:22+00:00Added an answer on June 16, 2026 at 2:02 am

    As you have printed, the data structure is not same in both cases. The original array itself shows that first element is an array with another array of string and second element is just a string. So while filtering and joining, you are getting ( "Day 1: " ) which represents an array where as you are expecting a string as "Day 1: ". Please check why your original array is having this kind of data structure.

    In order for your code to work, instead of

    (
            (
            "Day 1: "
        ),
        "Day 2: "
    )
    

    It should be,

    (
        "Day 1: ",
        "Day 2: "
    )
    

    So you need to change the way, you are adding objects to NSUserDefaults.

    Instead of,

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    NSMutableArray *rowsarray2 = [[NSMutableArray alloc] initWithObjects:[defaults objectForKey:@"checkedrows"], nil]; 
    [rowsarray2 addObject:entry.date]; 
    [defaults setObject:rowsarray2 forKey:@"checkedrows"]; 
    [defaults synchronize];
    

    Try this,

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    NSMutableArray *rowsarray2 = [NSMutableArray arrayWithArray:[defaults objectForKey:@"checkedrows"]]; 
    [rowsarray2 addObject:entry.date]; 
    [defaults setObject:rowsarray2 forKey:@"checkedrows"]; 
    [defaults synchronize];
    

    Basically you were creating an array with previous array as an object instead of adding a new object to that same array.

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

Sidebar

Related Questions

i'm working on an iOS app which has a tableview containing facebook friends' list,
I'm building an app with iPod-like controls (play, pause, etc). The app has tableView
I have an app that has a TableView, NavigationView and TabBar running together. There
I have a tableView which has cells with phone numbers. The app is not
The iOS app Path has this really cool layered scrollView/tableView combination and I'm trying
In my Rails 3 app, I have a list of questions. Each question has
My app has 3 tabs, and the array that populates a tableView in third
I'm making an app which has a tableview and a DetailViewController. I'm using Apple's
My app has number of UITableViews embedded into NavigationController . After I updated to
I have an iPhone app that utilizes TableView to list tagged items that the

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.