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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:36:51+00:00 2026-06-07T15:36:51+00:00

I’m using a plist with an array of dictionaries to populate a TableView and

  • 0

I’m using a plist with an array of dictionaries to populate a TableView and a DetailView for selected cell in TableView (prototype cell). I want to add selected dictionary to favorites tab (another TableView) when the button for that is pushed. This is my code so far:

Code so far in the DetailViewController:

-(IBAction)FavoriteButton:(id)sender
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ItemSelected"
                                                    object:selectedObject];


}

Code so far to catch the objects in FavoritesViewController:

[[NSNotificationCenter defaultCenter] addObserverForName:@"ItemSelected"
                                                  object:nil
                                                   queue:[NSOperationQueue mainQueue]
                                              usingBlock:^(NSNotification* notif) {
                                              [favoritedObjects release];
                                              favoritedObjects = [[notif object] retain];
                                              [self.tableView reloadData];
                                          }];

//And populate the TableView with the objects:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
 return [favoritedObjects count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Favcell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

// Configure the cell...

NSString *cellValue = [favoritedObjects valueForKey:@"Name"];
cell.textlabel.text = cellValue;

return cell;
}

This shows 20 cells with the value from the Key: “Name” from the last Object in the DetailViewController I pressed “Add to Favorites” button for. For example if I add “Gato Negro” to favorites, it displays “Gato Negro” in 20 cells. if I then add “Luna” to fav, it replaces “Gato Negro” with “Luna” in the 20 cells in FavoritesViewController.. So how can I display them one by one in the favorites TableView?

And how can I make the NotificationCenter save the changes when the app is closed, so it remembers the favorites to next time?

It seems like it’s kind of a communication problem here somewhere.

  • 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-07T15:36:53+00:00Added an answer on June 7, 2026 at 3:36 pm

    You are posting the notification with the object selectedObject (which I assume is your dictionary). When you receive that notification, you are replacing your existing favorites with this object:

    favoritedObjects = [[notif object] retain];

    So in fact favoritedObjects now is the single selectedObject dictionary. This dictionary probably has 20 entries, so that’s why you end up with 20 cells.

    You need to make (at least) two changes for your code to work:

    1. Change that line above to add the notification object to your favoritedObjects array (I am assuming that this is an NSMutableArray), instead of replacing favoritedObjects with the selectedObject dictionary. You will also need to create an instance of favoritedObjects once (either on-demand when you first want to add something to it, e.g. check for favoritedObjects == nil and if it’s nil, create a new NSMutableArray, or create it in a suitable place such as viewDidLoad (at some point you’ll probably be saving and loading the favorites, too, so putting its creation it into one of the initialization methods is a good idea anyway, even if you’re not ready for persistent favorites yet).

    2. In tableView:cellForRowAtIndexPath: make use of the indexPath that is passed to you to actually get the correct entry from your favoritedObjects array.

    Also, your tableView:cellForRowAtIndexPath: is missing the code to create a new cell if there is no cell available to be dequeued. Perhaps you have just omitted this piece of code for your question here? In case you haven’t, you’ll need to add that code.

    It is also a good idea to start method names with a lowercase letter (-(IBAction)favoriteButton:(id)sender instead of -(IBAction)FavoriteButton:(id)sender, or even better: -(IBAction)favoriteButtonPressed:(id)sender) because that’s what everyone expects Objective-C methods to look like 🙂

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build

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.