Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crash at [self.window makeKeyAndVisible];

Tags:

ios

My application was running fine until today it started to crash at: [self.window makeKeyAndVisible]; in 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;
}

If I debug and step inside at [self.window makeKeyAndVisible], the next statement before crashing is "@synthesize window = _window;" in the same app delegate.

All the previous versions that used to work behave the same.

I restarted my computer and still the same is happening. I am using XCode 4.2. Is there anything in xcode setup that I may have accidentally changed?

Thanks for any help.

The following is the whole debug window:

`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) `
like image 208
saman01 Avatar asked Feb 29 '12 20:02

saman01


4 Answers

Another big cause of this is if you connected an object to something in a .xib and then deleted the object because you decided you didn't need it but forgot to destroy the connection.

like image 68
rowdog Avatar answered Sep 23 '22 12:09

rowdog


If you've created the project for iOS 6 and then you changed the deployment target to 5.1, it's the Autolayout from the .xibs.

Open each .xib, click on 'Show Utilities' button (3rd from the view group), then go to 'Show File Inspector' (first tab), tick off 'Use Autolayout' and change Deployment to 5.1. (see attached screenshot).

Tick off Use Autolayout

like image 31
Marius Avatar answered Sep 20 '22 12:09

Marius


This crash happened to me when I removed some IBOutlet properties that were linked up to my XIB.

If you get an error like this:

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 keyNonexistentPropertyNameHere.'

Find that referencing outlet in your XIB and remove it or re-add that property to your view controller.

like image 23
Tim R. Avatar answered Sep 19 '22 12:09

Tim R.


Maybe someone else can benefit from this. I've gotten this crash at makeKeyAndVisible and tried everything suggested here and anywhere else I could find. No success. Still crashes.

I did comment out the line that makeKeyAndVisible is on, but then the ViewController never loads.

Just to see what would happen, I split makeKeyAndVisible in two:

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

It crashes at the second line, so apparently iOS doesn't like the hidden key.

From the debugging console:

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

My expertise is in assembly language programming and Objective-C is pretty mysterious to me, so I don't know where to go from here.


More information: I moved this instruction down to just before the return at the end of application didFinishLaunching... and now it is crashing on this:

self.window.rootViewController = self.viewController;
like image 23
Cliff Harris Avatar answered Sep 23 '22 12:09

Cliff Harris