PDA

View Full Version : KVO binding from code to controls not working




TenaciousG
Oct 14, 2009, 01:14 PM
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 :

...
- (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:


...
@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;
...



PhoneyDeveloper
Oct 14, 2009, 01:38 PM
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?

TenaciousG
Oct 15, 2009, 07:53 AM
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.