0

I'm trying to observe interface orientation by KVO of UIViewController from other object by this code :

[((UIViewController *)self.delegate) addObserver:self forKeyPath:@"interfaceOrientation" options:NSKeyValueObservingOptionNew context:NULL];

and implementing the function :

-(void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context 
{
 if ([keyPath isEqual:@"interfaceOrientation"]) 
  {
    // do something    
  }
}

The method is called only in the first time , although i can see that the property interfaceOrientation of the delegate change while i rotating the phone .

Why?

Please help !

Thanks!!!!

Rivka Schwartz
  • 524
  • 5
  • 15

1 Answers1

1

Why are you doing this with KVO? UIViewControllers have built in support for this. Look at

  //iOS6 only
 - (BOOL)shouldAutomaticallyForwardRotationMethods
 {
    return YES;
 }

and also addChildViewController:

Jack Freeman
  • 1,414
  • 11
  • 18