KVO binding from code to controls not working

Discussion in 'iOS Programming' started by TenaciousG, Oct 14, 2009.

  1. TenaciousG macrumors newbie

    Oct 14, 2009
    When restoring my application state from NSUserdefaults, I call a method in my ViewController which updates properties on controls in the view. These changes do not show up in the view, however. From my understanding of KVO the controls should update in the view as they are bound to synthesized properties in my viewmodel.
    Can anyone spot the error?

    ViewModel .m :
    - (void)restoreCalendarWithSelectionArray:(NSArray *)selectionArray
    	for (int i = 0; i < [selectionArray count] -1; i++) {
    		//update the selected ones
    		if ([[selectionArray objectAtIndex:i] integerValue] == 1)
    			switch (i) {
    				case 0:
    					button1.hidden = TRUE;
    					button1.enabled = FALSE;
    					imageView.hidden = FALSE;
    					 [imageView setImage:image2];

    ViewModel .h:

    @interface MyViewController : UIViewController{
    	UIImageView *imageView;
    	UIImageView *animation;
    	UIImage *image1;
    	UIImage *image2;
    	AVAudioPlayer *audioPlayer;
    	SystemSoundID currentSoundFXID;
    	UIButton *button1;
    	UIButton *button2;
    	UIButton *button3;
    @property (nonatomic, retain) IBOutlet UIImageView *imageView;
    @property (nonatomic) SystemSoundID currentSoundFXID;
    @property (nonatomic, retain) IBOutlet UIButton *button1;
    @property (nonatomic, retain) IBOutlet UIButton *button2;
    @property (nonatomic, retain) IBOutlet UIButton *button3;
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    At what point is restoreCalendarWithSelectionArray called?

    Are you sure that the controls exist at that point?

    What value does button1 have when that method is called?
  3. TenaciousG thread starter macrumors newbie

    Oct 14, 2009
    restoreCalendarWithSelectionArray is called from AppDelegates applicationDidFinishLaunching, so I assume the controls are loaded by then.

    I'm at work now, can't remember what value the button1 has when called, but I can check later.

Share This Page