应用程序崩溃并显示“无法恢复先前选择的帧"信息 [英] App crash with "Unable to restore previously selected frame" message

查看:25
本文介绍了应用程序崩溃并显示“无法恢复先前选择的帧"信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么该代码会导致应用崩溃.

I can't figure out why that code leads to app crash.

AppDelegate.h

AppDelegate.h

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.rootViewController = [[[RootViewController alloc]init]autorelease];

    [self.window setRootViewController:self.rootViewController];


    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

这是 RootViewController.m 代码

Here is RootViewController.m code

-(void)loadView
{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 10, 10)];
    [view setBackgroundColor:[UIColor lightGrayColor]];
    [self.view addSubview:view];
    [view release];
}

我在调试器中收到该消息

I get that message in the debugger

Unable to restore previously selected frame.

推荐答案

loadView 应该设置视图.当 self.view 为 nil 时调用它.现在你正在调用 [self.view addSubview:view]; UIKit 调用 loadView,这会创建一个无限递归.您应该在此处执行 self.view = view;.

loadView is supposed to set the view. It is called when self.view is nil. Now you're calling [self.view addSubview:view]; UIKit calls loadView, and that creates an infinite recursion. You're supposed to do self.view = view; here.

这篇关于应用程序崩溃并显示“无法恢复先前选择的帧"信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆