我有一个应用程序,我在其中以编程方式创建ImageView。当我尝试创建它时,我收到错误:
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)
以下是添加图像视图的代码:
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];
}
尽我所能,我还没有找到解决方案。非常感谢帮助。
答案 0 :(得分:1)
您正尝试从xib访问某些视图,但尚未创建其插座。
答案 1 :(得分:0)
似乎错误与背景无关。您的xib文件似乎有问题 您的xib文件是否包含名为backgroundImage的内容?
答案 2 :(得分:0)
如上所述,检查您是否使用backgroundImage iVar执行任何操作。