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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:01:22+00:00 2026-06-10T09:01:22+00:00

i have a problem with KVO in an iOS App. I can’t seem to

  • 0

i have a problem with KVO in an iOS App. I can’t seem to get it right. What i’m trying to do:

i have a MenuViewController (revealable on the left side, like facebook app) that observes (and displays) a global value. I tried some different approaches but my App allways crashes (at different points and for different reasons thow). I will describe those below.

Note: I’m using [object addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil] to register the MenuViewController as an observer and [object removeObserver:self forKeyPath:@"name" context:nil] to deregister.

Szenario 1:

o I put the registration as an observer in the -viewWillAppear method and the removeObserver code in -viewWillDisappear.
o When the value changes and the i have completely changes the rootViewController i get an error “message sent to deallocated instance”. So i guess MenuViewController is still registered as an observer.

Szenario 2:

o As a result i putted the removeObserver code into the dealloc function (and later also moved the addObserver part into viewDidLoad)
o Now i get a different error: cannot remove observer for key path “name” from <…> because it is not registered as an observer.

So maybe somebody could give me a hint on my problem and how to do KVO the right way. Unfortunately the docs couldn’t help me so far.

Thanks!

  • 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-10T09:01:24+00:00Added an answer on June 10, 2026 at 9:01 am

    Your view controller does not always get viewWillDisappear before it gets dealloced. Your technique is close to what you should do. You can get multiple viewDidLoad messages (if system unloads your view) and viewWillAppear, but only one dealloc.

    What you should do for now is use a BOOL ivar, didObserve. In viewDidLoad, if didObserve == NO, observe the object, set the flag didObserve=YES, then add a log

    NSLog(@"DID observe %@", object);
    

    In dealloc (or anywhere else you want to), add

    if(didObserve) {
      unobserve
      NSLog(@"UNDID observe %@", object);
    }
    

    Now run your app, verify you get the two messages, verify that object is the same object each time (and not nil). This should help you get it sorted out. You might even put a log in ‘observeValueForKeyPath:’ logging any changes to that variable.

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

Sidebar

Related Questions

I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar
I have problem with jCaret plugin in IE. jCaret downloads I want to get
i have problem passing data from one page to another using GET, for example
I have problem with infinite loop in Grails app when rejectIfNoRule = true I
Using iOS 4.3 on an ipad app I have a custom NSOperation that uses
Have problem with linq expressions. I want to get from db some data ordered
I have problem positioning left sidebar (variating height DIV) ON IE6. Main needs: 1.
I have problem with types in my schema when trying to use xsd:any element
I have problem running my app on Android 2.3 (Gingerbread). The app has a
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE

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.