iOS 旋转手机崩溃

标签 ios xcode

我只支持纵向 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 的一部分 SHKActivityIndi​​cator,它有一个通知正在捕获屏幕旋转及其导致问题的选择器:

[[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/

相关文章:

ios - 在后台解析后数据未加载到 UITableView 中

ios - 如何设置 NSPopupButton 菜单项的颜色

ios - 从 NSAttributedString swift 3 生成多页 PDF

iphone - 找不到 -lXXX 的库

ios - 从值包含字符串的核心数据中获取

ios - 尝试在编辑模式下 UITableViewCellSelectionStyleDefault 中需要颜色时保留 UITableViewCellSelectionStyleNone

javascript - 无法在 iOS 模拟器上运行简单的基于 KineticJs 的 Cordova/PhoneGap 应用程序

c++ - lldb/Xcode : how to print thread index, id 或名称?

iphone - 在多台计算机上为 iOS 开发,在单个设备上测试,建议?

ios - 更新到 Xcode 10.2 后 : Invalid Toolchain error when trying to submit app to App Store