KVO binding from code to controls not working

Discussion in 'iPhone/iPad Programming' started by TenaciousG, Oct 14, 2009.

  1. macrumors newbie

    Joined:
    Oct 14, 2009
    #1
    Hi!
    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 :
    Code:
    ...
    - (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];
    					break;
    ...
    

    ViewModel .h:

    Code:
    ...
    @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. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    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. thread starter macrumors newbie

    Joined:
    Oct 14, 2009
    #3
    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