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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:09:16+00:00 2026-05-31T16:09:16+00:00

I have an iPad app that has a UITableViewController that implements the NSFetchedResultsControllerDelegate .

  • 0

I have an iPad app that has a UITableViewController that implements the NSFetchedResultsControllerDelegate. (Mostly using the CoreDataTableViewController code from the Stanford iOS classes.)

I have a secondary model object (self.locations) that is an array of Location objects which is a subclass of NSManagedObjects. This array drives the content of a UISegmentedControl that filters my main fetchedResultsContoller.

It is possible to modify the contents of self.locations via a popover. I want to set up some sort of observing so that my main UITableViewController can watch for changes in the objects stored in self.locations and reload the UISegmentedControl if necessary.

This might also result in a reload of the main data in the table, so I want to be careful to not reload on every little modification.

I think I understand how to setup KVO on a single NSManagedObject but I’m not sure how to do it on object contained in an array. I understand that I can use another NSFetchedResultsController, but my self.locations object does not drive a second UITableView, so I’m not sure it makes sense.

  • 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-31T16:09:17+00:00Added an answer on May 31, 2026 at 4:09 pm

    It is pretty straight-forward to observe a one-to-many relationship if all you want to know if objects are added, removed, replaced, or re-ordered. In fact, it is done exactly the same way as with a normal object:

    [self addObserver:self
           forKeyPath:@"locations"
              options:0
              context:NULL];
    

    Then implement the following to receive notifications (partially copied from Apple docs):

    - (void)observeValueForKeyPath:(NSString *)keyPath
                          ofObject:(id)object
                            change:(NSDictionary *)change
                           context:(void *)context {
    
        if ([keyPath isEqual:@"locations"]) {
            // Your custom code here.
        }
    
        // Be sure to call the superclass's implementation *if it implements it*.
        [super observeValueForKeyPath:keyPath
                             ofObject:object
                               change:change
                               context:context];
    }
    

    Don’t forget to stop observing at some point:

    [self removeObserver:self forKeyPath:@"locations"];
    

    And, although you didn’t ask, if you want to know if any of the objects contained in the relationship have changed (and not just the NSSet that you are watching here) then you have to observe the individual objects.

    EDIT

    Per your comment, you do want to observe the individual objects. This is fairly straight-forward for “normal” objects, but a managed object takes a bit more work because you have to observe the individual keys in the object, which would look something like this:

    - (void)observeManagedObject:(NSManagedObject *)myObject {
        NSArray *myObjectKeys = [[[myObject entity] attributesByName] allKeys];
        for (NSString *key in myObjectKeys) {
            [myObject addObserver:self 
                        forKeyPath:key 
                           options:0 
                           context:nil];
        }
    }
    

    And then you observe all of the NSManagedObjects in the array like this:

    for (NSManagedObject *object in myArray) {
        [self observeManagedObject:object];
    }
    

    Do the reverse to stop observing the keys on the managed object!

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

Sidebar

Related Questions

I have an iPad app that receives data using UDP sockets. And it has
I have an ios app that has a target of both iphone and ipad.
I have this iPad app using Storyboard. There are some file that are marked
I have a universal iOS app with a custom view that has three buttons,
I have created an iPad app that has 10 view controllers that swipe left
I have an iPad app that has 4 buttons on the left side that
I have an iPad app that has draggable UIViews contained in a larger parent
I have an iPad app that has an MKMapView embedded in a UINavigationController which
I have an iPad app that contains a webview. The webview's page has a
Our company created an iOS app that has an iPhone version and an iPad

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.