崩溃在[self.window makeKeyAndVisible];

时间:2012-02-29 20:46:37

标签: ios

我的应用程序运行良好,直到今天它开始崩溃:     [self.window makeKeyAndVisible]; 在app delegate。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    self.viewController = [[ViewControllerWordHelper alloc] initWithNibName:@"ViewControllerWordHelper_iPhone1" bundle:nil];
} else {
    self.viewController = [[ViewControllerWordHelper alloc] initWithNibName:@"ViewControllerWordHelper_iPhone" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}

如果我调试并在[self.window makeKeyAndVisible]中进入,则崩溃前的下一个语句是“@synthesize window = _window;”在同一个应用代表中。

过去工作的所有以前版本的行为都相同。

我重新启动了计算机,但仍然发生了同样的情况。我正在使用XCode 4.2。在xcode设置中是否有任何我可能意外更改的内容?

感谢您的帮助。

以下是整个调试窗口:

`GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug 15 16:03:10 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 440.
Pending breakpoint 3 - ""ViewControllerWordHelper.m":136" resolved
Pending breakpoint 4 - ""AppDelegate.m":41" resolved
Pending breakpoint 5 - ""ViewControllerWordHelper.m":27" resolved
Pending breakpoint 6 - ""ViewControllerWordHelper.m":166" resolved
Current language:  auto; currently objective-c
(gdb) `

5 个答案:

答案 0 :(得分:21)

另一个重要原因是如果你将一个对象连接到.xib中的某个东西然后删除了该对象,因为你决定不需要它但忘记破坏连接。

答案 1 :(得分:4)

如果您已经为iOS 6创建了项目,然后将部署目标更改为5.1,那么它就是.xibs中的Autolayout。

打开每个.xib,单击“Show Utilities”按钮(视图组中的第3个),然后转到“Show File Inspector”(第一个选项卡),勾选“Use Autolayout”并将Deployment更改为5.1。 (见附页截图)。

Tick off Use Autolayout

答案 2 :(得分:2)

当我删除了一些链接到我的XIB的IBOutlet属性时,发生了这次崩溃。

如果您收到如下错误:

2012-09-20 09:45:07.920 AppName[78792:c07] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0xa2b3000> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key NonexistentPropertyNameHere.'

在XIB中找到引用插座并将其删除或将该属性重新添加到视图控制器。

答案 3 :(得分:1)

也许其他人可以从中受益。我在makeKeyAndVisible上遇到了这个崩溃,并尝试了这里和我能找到的任何其他地方的所有建议。没有成功。仍然崩溃。

我确实注释了makeKeyAndVisible所在的行,但ViewController从未加载。

为了看看会发生什么,我将makeKeyAndVisible分成两部分:

[self.window makeKeyWindow];
self.window.hidden = NO;

它在第二行崩溃,显然iOS不喜欢隐藏的密钥。

从调试控制台:

0   CoreFoundation                      0x0173b5e4 __exceptionPreprocess + 180
1   libobjc.A.dylib                     0x014be8b6 objc_exception_throw + 44
2   CoreFoundation                      0x017cb6a1 -[NSException raise] + 17
3   Foundation                          0x0117f9ee -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4   Foundation                          0x010ebcfb _NSSetUsingKeyValueSetter + 88
5   Foundation                          0x010eb253 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
6   Foundation                          0x0114d70a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412

我的专业知识是汇编语言编程,而Objective-C对我来说非常神秘,所以我不知道从哪里开始。


更多信息: 我把这条指令移到了应用程序结束时返回之前的didFinishLaunching ......现在它正在崩溃:

self.window.rootViewController = self.viewController;

答案 4 :(得分:0)

这主要是因为你还没有为ViewControllerWordHelper_iPhone1 / ViewControllerWordHelper_iPhone创建XIB。

否则您可以通过这种方式更改代码

self.viewController = [[ViewControllerWordHelper alloc] initWithNibName:nil bundle:nil];
} else {
    self.viewController = [[ViewControllerWordHelper alloc] initWithNibName:nil bundle:nil];
}