【发布时间】:2014-09-25 16:27:28
【问题描述】:
我有一个 iOS 应用程序,它在我的 ViewController 中包含一个 UIView 和一个子 UIView。 (在情节提要中创建)。
我想更改 IBAction 中子视图的背景颜色,但应用程序崩溃了。这是我的代码:
-(IBAction)open_popup {
[popupView setBackgroundColor:[UIColor colorWithRed:0 green:255 blue:0 alpha:1.0]];
}
更新 - 这就是我声明弹出视图的方式
IBOutlet UIView *popupView; // in my header file
更新 - 这是我遇到的错误
2014-08-02 18:20:39.009 ZenApp[1373:60b] 4
2014-08-02 18:20:39.011 ZenApp[1373:60b] -[NSCFType CGColor]: unrecognized selector sent to instance 0x10c896a60
2014-08-02 18:20:39.015 ZenApp[1373:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType CGColor]: unrecognized selector sent to instance 0x10c896a60' *
First throw call stack: (
0 CoreFoundation 0x0000000101f05495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000101c6499e objc_exception_throw + 43
2 CoreFoundation 0x0000000101f9665d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000101ef6d8d ___forwarding_ + 973
4 CoreFoundation 0x0000000101ef6938 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010086466c -[UIView(Hierarchy) _setBackgroundColor:] + 37
6 ZenApp 0x00000001000036f8 -[ViewController change_colour_stage_4] + 168
7 ZenApp 0x0000000100002e5d -[ViewController change_colours] + 205
8 ZenApp 0x00000001000030db -[ViewController change_colour_stage_1] + 587
9 ZenApp 0x0000000100002d17 -[ViewController viewDidLoad] + 3079
10 UIKit 0x000000010090759e -[UIViewController loadViewIfRequired] + 562
11 UIKit 0x0000000100907777 -[UIViewController view] + 29
12 UIKit 0x00000001008502d2 -[UIWindow handleStatusBarChangeFromHeight:toHeight:] + 530
13 UIKit 0x0000000100851ca6 +[UIWindow _noteStatusBarHeightChanged:oldHeight:forAutolayoutRootViewsOnly:] + 230
14 UIKit 0x000000010086a92f +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 460
15 UIKit 0x000000010086abc5 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:animations:completion:] + 59
16 UIKit 0x0000000100813bf5 -[UIApplication _setStatusBarHidden:animationParameters:changeApplicationFlag:] + 478
17 UIKit 0x0000000100847c33 -[UIWindow _setHidden:forced:] + 221
18 UIKit 0x0000000100850ffa -[UIWindow makeKeyAndVisible] + 51
19 UIKit 0x000000010080cc98 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1788
20 UIKit 0x0000000100810a0c -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 660
21 UIKit 0x0000000100821d4c -[UIApplication handleEvent:withNewEvent:] + 3189
22 UIKit 0x0000000100822216 -[UIApplication sendEvent:] + 79
23 UIKit 0x0000000100812086 _UIApplicationHandleEvent + 578
24 GraphicsServices 0x000000010386671a _PurpleEventCallback + 762
25 GraphicsServices 0x00000001038661e1 PurpleEventCallback + 35
26 CoreFoundation 0x0000000101e87679 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 41
27 CoreFoundation 0x0000000101e8744e __CFRunLoopDoSource1 + 478
28 CoreFoundation 0x0000000101eb0903 __CFRunLoopRun + 1939
29 CoreFoundation 0x0000000101eafd83 CFRunLoopRunSpecific + 467
30 UIKit 0x00000001008102e1 -[UIApplication _run] + 609
31 UIKit 0x0000000100811e33 UIApplicationMain + 1010
32 ZenApp 0x0000000100004413 main + 115
33 libdyld.dylib 0x00000001034e65fd start + 1
34 ??? 0x0000000000000001 0x0 + 1 )
libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
感谢您抽出宝贵时间,丹。
【问题讨论】:
-
嗯.. 控制台崩溃时会显示什么?这是你的第一个线索。
-
确保 popupView 确实指向 UIView。
-
@Tander 我已经用我得到的错误更新了我的问题。你知道怎么回事吗?
-
@Anna 你到底是什么意思?如果您的意思是接口构建器和引用出口,那么是的,它已连接。
-
与您的问题无关;这不是设置颜色的方法。如果您想在通道中使用全彩,请将其设置为
1.0而不是255。如果你想Red:120做120.0/255
标签: ios objective-c uiview uicolor