Reputation: 37
I have a app in which I am programaticly creating a ImageView. When I try to create this I get the error:
2013-12-23 21:22:13.674 MagnetFall[22343:70b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<GameScreenViewController 0xa98eae0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key backgroundImage.'
*** First throw call stack:
(
0 CoreFoundation 0x019695e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x016ec8b6 objc_exception_throw + 44
2 CoreFoundation 0x019f96a1 -[NSException raise] + 17
3 Foundation 0x013ad9ee -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 Foundation 0x01319cfb _NSSetUsingKeyValueSetter + 88
5 Foundation 0x01319253 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
6 Foundation 0x0137b70a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
7 UIKit 0x006fca15 -[UIRuntimeOutletConnection connect] + 106
8 libobjc.A.dylib 0x016fe7d2 -[NSObject performSelector:] + 62
9 CoreFoundation 0x01964b6a -[NSArray makeObjectsPerformSelector:] + 314
10 UIKit 0x006fb56e -[UINib instantiateWithOwner:options:] + 1417
11 UIKit 0x0056d605 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
12 UIKit 0x0056ddad -[UIViewController loadView] + 302
13 UIKit 0x0056e0ae -[UIViewController loadViewIfRequired] + 78
14 UIKit 0x0056e5b4 -[UIViewController view] + 35
15 UIKit 0x0057dab9 -[UIViewController shouldAutorotate] + 36
16 UIKit 0x0057de01 -[UIViewController _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation:] + 297
17 UIKit 0x008025e5 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:] + 2330
18 UIKit 0x0057a0fc -[UIViewController presentViewController:withTransition:completion:] + 6433
19 UIKit 0x0057a61f -[UIViewController presentViewController:animated:completion:] + 130
20 UIKit 0x0057a65f -[UIViewController presentModalViewController:animated:] + 56
21 UIKit 0x0099ee16 -[UIStoryboardModalSegue perform] + 271
22 UIKit 0x0098f07e -[UIStoryboardSegueTemplate _perform:] + 174
23 UIKit 0x0098f0f9 -[UIStoryboardSegueTemplate perform:] + 115
24 libobjc.A.dylib 0x016fe874 -[NSObject performSelector:withObject:withObject:] + 77
25 UIKit 0x0045c0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
26 UIKit 0x0045c04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
27 UIKit 0x005540c1 -[UIControl sendAction:to:forEvent:] + 66
28 UIKit 0x00554484 -[UIControl _sendActionsForEvents:withEvent:] + 577
29 UIKit 0x00553733 -[UIControl touchesEnded:withEvent:] + 641
30 UIKit 0x0049951d -[UIWindow _sendTouchesForEvent:] + 852
31 UIKit 0x0049a184 -[UIWindow sendEvent:] + 1232
32 UIKit 0x0046de86 -[UIApplication sendEvent:] + 242
33 UIKit 0x0045818f _UIApplicationHandleEventQueue + 11421
34 CoreFoundation 0x018f283f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
35 CoreFoundation 0x018f21cb __CFRunLoopDoSources0 + 235
36 CoreFoundation 0x0190f29e __CFRunLoopRun + 910
37 CoreFoundation 0x0190eac3 CFRunLoopRunSpecific + 467
38 CoreFoundation 0x0190e8db CFRunLoopRunInMode + 123
39 GraphicsServices 0x02f1a9e2 GSEventRunModal + 192
40 GraphicsServices 0x02f1a809 GSEventRun + 104
41 UIKit 0x0045ad3b UIApplicationMain + 1225
42 MagnetFall 0x000052dd main + 141
43 libdyld.dylib 0x03afe70d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Here is the code for adding the Image View:
UIImageView *background;
- (void)viewDidLoad
{
[super viewDidLoad];
{ //Loads the Background.
background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BackgroundAll.png"]];
background.center = CGPointMake(160, 284);
[self.view addSubview:background];
}
Try as I might, I have not figured out a solution. Help would be greatly appreciated.
Upvotes: 0
Views: 4553
Reputation: 7706
Please note that I found that I had accidentally added a connection that was not wired up at all:
Upvotes: 0
Reputation: 453
You are trying to access some view from your xib but you have not created its outlet.
Upvotes: 1
Reputation: 88
As mentioned above, check if your doing anything with backgroundImage iVar.
Upvotes: 0
Reputation: 664
It seems the error is nothing to do with the background. It seems something wrong with your xib file.
Does your xib file contains something named as backgroundImage?
Upvotes: 0