我希望在设备方向发生变化时收到通知。我已经设置了一个假设接收通知的测试方法。我正在尝试几个不同的观察者来实现这一点,但他们都没有工作。为什么 testMethod 没有被解雇?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
// register for orientation change notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(testMethod) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(testMethod)
name: UIApplicationWillChangeStatusBarOrientationNotification
object: nil];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(testMethod)
name: UIApplicationDidChangeStatusBarOrientationNotification
object: nil];
}
- (void)testMethod
{
NSLog(@"phone was rotated");
}