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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:56:02+00:00 2026-06-11T11:56:02+00:00

In many of my UIViewControllers , I update certain controls based on the state

  • 0

In many of my UIViewControllers, I update certain controls based on the state of my data. For example, I might have an edit button on a UITableViewController that should only be enabled when there is one or more items. Or perhaps I want to limit the number of items that can be added, and disable the ‘add’ button otherwise.

Every time I add or delete an item (or take any other action that can add/remove items), I have to remember to update any controls that might need enabling/disabling. This is trivial for the most part, but doesn’t feel comfortable – there is a lot of repetition, and I have to remember to add the calls to updateControlEnabled (or whatever) whenever I add new functionality that might affect the data.

And then I noticed NSManagedObjectContextObjectsDidChangeNotification. Reading the docs, it looks like I can receive a notification whenever something changes in my managed object context. This seems ideal, but I have a few questions:

  1. Is this an appropriate use of
    NSManagedObjectContextObjectsDidChangeNotification?

  2. Should I anticipate any performance impact if a controller
    subscribes to these and parses each one to see if it needs to update
    the UI? I will be checking the userInfo for every change, instead of
    only those that I know I will care about.

  3. Where should I subscribe to the notifications? My UIViewController has a
    reference to the context, which helps, but I don’t know where to
    subscribe (loadView? viewDidLoad? init?) such that the view
    controller will always have one and only one subscription.
  4. The view controller will continue to receive and process notifications
    when it’s offscreen – enabling and disabling controls as the
    data model is affected from elsewhere. Is this ok?

I guess I’m mostly just wondering if anyone else uses this approach and if so, what their experience is.

  • 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-11T11:56:03+00:00Added an answer on June 11, 2026 at 11:56 am

    Q) Is this an appropriate use of NSManagedObjectContextObjectsDidChangeNotification?

    A) Yes – I used it on OSX for a similar purpose.

    Q) Should I anticipate any performance impact if a controller subscribes to these and parses each one to see if it needs to update the UI? I will be checking the userInfo for every change, instead of only those that I know I will care about.

    A) NO – it will normally be a very small set of objects – ones that were directly changed.

    Q) Where should I subscribe to the notifications? My UIViewController has a reference to the context, which helps, but I don’t know where to subscribe (loadView? viewDidLoad? init?) such that the view controller will always have one and only one subscription.

    A) Well, you cannot affect the UI til the view shows – so probably viewDidLoad or viewWillAppear. The problem with the later is you may get it a few times depending on push/pops, so maybe I’d do it in viewDidLoad.

    Q) The view controller will continue to receive and process notifications when it’s offscreen – enabling and disabling controls as the data model is affected from elsewhere. Is this ok?

    A) Sure – when the view reappears all the elements will be setup correctly.

    What you want to do is a classical use of that notification. Just check the thread it comes in on – if its not the mainThread then you want to make all your changes in a block posted to the mainThread.

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

Sidebar

Related Questions

I have an application that has many views (Using tab bar controller). I want
Is there a method that is always called in Cocoa? Many classes have init
I have a UINavigationController that pushes a custom UITableViewController onto the stack. This pushed
First of all I have seen that there are many questions about unrecognized selector
I have a uiviewcontroller with many UIButtons that are meant to be selected and
many Places in the sample code i have seen 2 different way of @synthesize
Many threads have access to summary . Each thread will have an unique key
Many methods in the BCL are marked with the [MethodImpl(MethodImplOptions.InternalCall)] attribute. This indicates that
Many different representation of parameters in python such as : urllib2.urlopen(url[, data][, timeout]) urllib2.build_opener([handler,
I have a UIViewController that has an UIPopoverController that has an UINavigationController then a

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.