gpt4 book ai didi

objective-c - 应用程序崩溃并显示 "Unable to restore previously selected frame"消息

转载 作者:行者123 更新时间:2023-11-28 19:20:25 26 4
gpt4 key购买 nike

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

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代码

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

我在调试器中收到该消息

Unable to restore previously selected frame.

Here is screenshot

最佳答案

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

关于objective-c - 应用程序崩溃并显示 "Unable to restore previously selected frame"消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9349149/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com