假設我在nib文件someNib.xib中。爲了讓我能夠告訴我們,如果設備的方向再變,我把這個視圖中沒有加載方法:停止調用由beginGeneratingDeviceOrientationNotifications生成的方法
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationChanged)
name:UIDeviceOrientationDidChangeNotification object:nil];
這行做的是,它會調用deviceOrientationChanged方法加班設備旋轉。我的deviceOrientationChanged方法看起來像:
-(void) deviceOrientationChanged{
if(self.view.frame.size.width<800)
{
//means device is on portrait mode
} else {
//means device is on landscape mode
}
}
所以一切工作很好,這個筆尖文件。問題來了,當我加載另一個筆尖文件爲:
// release allocated variables
// VCHome is the name of the nib file
VCHome *control = [VCHome alloc];
[control initWithNibName:@"VCHome" bundle:nil];
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController:control];
[self presentModalViewController:navControl animated:YES];
[navControl setNavigationBarHidden:YES];
[control release];
[navControl release];
直到這一點,一切正常。我現在在一個新的筆尖文件上,我可以與VCHome進行交互。
爲什麼當我使用VCHome nib文件並旋轉我的設備時,deviceOrientationChanged方法被調用?當我加載VCHome nib文件時,我應該釋放someNib(最後一個nib),以便不調用此方法。我不打算再使用一些Nib,並希望我的VCHome筆尖的行爲像我從未加載過一些Nib一樣。