我只支持纵向 ATM,旋转设备时出现这些错误:
[__NSCFData setProperRotation]: unrecognized selector sent to instance 0x2dc890
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData setProperRotation]: unrecognized selector sent to instance 0x2dc890'
这是在 iOS5.1 中。最初我只是保留默认的纵向子句,但将其更改为:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationPortrait) { // Or whatever orientation it will be presented in.
return YES;
}
return NO;
}
顺便说一句,我正在使用 ARC。
希望这有助于阻止崩溃。我的 info.plist 有 portrait 和 portrait 颠倒的。除了我的主视图有多个 ViewControllers 并将其设置为:
self.wantsFullScreenLayout=YES;
有什么想法吗?提前致谢。
我的项目从 appdelegate 添加了主视图:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
mainViewController=[[MainViewController alloc] init];
[self.window addSubview:mainViewController.view];
我在 mainViewController 上有 2 个 ViewController,我使用导航 Controller 来推送多个 ViewController:
- (void) loadActionsView {
NSArray* views = [self.navigationController viewControllers];
if ([views containsObject: actionsPanelViewController])
{
[self.navigationController popToViewController:actionsPanelViewController animated:YES];
} else {
[self.navigationController pushViewController:actionsPanelViewController animated:YES];
}
[[StateModel stateModel] setCurrentScreenIndex:0];
顺便说一句,这是第一个 View 。
找到解决方案/问题的更新 2:
我正在使用 SHK 的一部分 SHKActivityIndicator,它有一个通知正在捕获屏幕旋转及其导致问题的选择器:
[[NSNotificationCenter defaultCenter] addObserver:currentIndicator selector:@selector(setProperRotation) name:UIDeviceOrientationDidChangeNotification object:nil];
最佳答案
听起来您的 ViewController 已释放,另一个对象收到 setProperRotation 消息。检查您的 ViewController 是否还活着。
mainViewController=[[MainViewController alloc] init];
[self.window addSubview:mainViewController.view];
问题来了。您只添加 View 。 ARC 认为您不再需要 MainViewController。
- 将 MainViewController 作为类变量或
设置window.rootViewController
self.window.rootViewController = mainViewController;
关于iOS 旋转手机崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11221252/