sendActionsForControlEvents中的UIControl子类问题
Posted
技术标签:
【中文标题】sendActionsForControlEvents中的UIControl子类问题【英文标题】:UIControl sub Class problem in sendActionsForControlEvents 【发布时间】:2011-08-20 15:18:02 【问题描述】:我遇到了与Link 中提到的相同的问题我有 UIControl(名为 GCDatePickerControl),我还有另一个类(名为 GCCalendarPortraitView) 在 GCCalendarPortraitView 类中我有代码
dayPicker = [[GCDatePickerControl alloc] init];
dayPicker.frame = CGRectMake(0, 0, self.view.frame.size.width, 0);
dayPicker.autoresizingMask = UIViewAutoresizingNone;
dayPicker.date = date;
[dayPicker addTarget:self action:@selector(datePickerDidChangeDate:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:dayPicker];
其中 dayPicker 是 GCDatePickerControl 类的对象
在 GCDatePickerControl 我有代码
[self sendActionsForControlEvents:UIControlEventValueChanged];
如果我评论以下任何一行,我的代码应用程序运行良好
[self sendActionsForControlEvents:UIControlEventValueChanged];
[dayPicker addTarget:self action:@selector(datePickerDidChangeDate:) forControlEvents:UIControlEventValueChanged];
但是如果我取消注释我的 App crush show 在控制台上显示这个结果
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CALayerArray datePickerDidChangeDate:]: unrecognized selector sent to instance 0x7a2cc30'
*** Call stack at first throw:
(
0 CoreFoundation 0x02c86919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x02dd45de objc_exception_throw + 47
2 CoreFoundation 0x02c8842b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x02bf8116 ___forwarding___ + 966
4 CoreFoundation 0x02bf7cd2 _CF_forwarding_prep_0 + 50
5 UIKit 0x00303e14 -[UIApplication sendAction:to:from:forEvent:] + 119
6 UIKit 0x0038d6c8 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x0038fb4a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
8 UIKit 0x0038d67f -[UIControl sendActionsForControlEvents:] + 49
9 CalendarApp 0x00016d7f -[GCDatePickerControl buttonPressed:] + 437
10 UIKit 0x00303e14 -[UIApplication sendAction:to:from:forEvent:] + 119
11 UIKit 0x0038d6c8 -[UIControl sendAction:to:forEvent:] + 67
12 UIKit 0x0038fb4a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
13 UIKit 0x0038e6f7 -[UIControl touchesEnded:withEvent:] + 458
14 UIKit 0x003272ff -[UIWindow _sendTouchesForEvent:] + 567
15 UIKit 0x003091ec -[UIApplication sendEvent:] + 447
16 UIKit 0x0030dac4 _UIApplicationHandleEvent + 7495
17 GraphicsServices 0x03413afa PurpleEventCallback + 1578
18 CoreFoundation 0x02c67dc4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
19 CoreFoundation 0x02bc8737 __CFRunLoopDoSource1 + 215
20 CoreFoundation 0x02bc59c3 __CFRunLoopRun + 979
21 CoreFoundation 0x02bc5280 CFRunLoopRunSpecific + 208
22 CoreFoundation 0x02bc51a1 CFRunLoopRunInMode + 97
23 GraphicsServices 0x034122c8 GSEventRunModal + 217
24 GraphicsServices 0x0341238d GSEventRun + 115
25 UIKit 0x00311b58 UIApplicationMain + 1160
26 CalendarApp 0x000025c4 main + 102
27 CalendarApp 0x00002555 start + 53
28 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
我无法找出我的问题请任何人帮助我谢谢
【问题讨论】:
【参考方案1】:当控件尝试调用给定目标上的选择器并且该选择器不存在时,会发生此错误。在您的情况下,您是否检查过“datePickerDidChangeDate:”是否存在?这可能只是一个拼写错误。
【讨论】:
是的 datePickerDidChangeDate: 确实存在 我已经下载了日历的示例项目运行良好但是当我将它集成到我的项目中时它开始在这条线上崩溃 [self sendActionsForControlEvents:UIControlEventValueChanged];当我评论这一行时,我的代码可以正常工作 在调用这个方法之前目标是否已经释放? 我正在使用此链接link 我所做的唯一更改是在此示例应用程序中,在主窗口中制作日历并在视图控制器中制作日历。这就是我面临这个问题的原因吗,因为正如你所说的那样,它可能会在调用之前获得释放。我已经检查过了。目标没有得到释放。以上是关于sendActionsForControlEvents中的UIControl子类问题的主要内容,如果未能解决你的问题,请参考以下文章