从 UISlider 实现 valueChanged 操作时出现无法识别的选择器错误
我有一个非常简单的 UIViewController
子类:
@interface RoastChickenViewController : UIViewController {
IBOutlet UISlider *weightSlider;
}
@property (nonatomic,retain) UILabel *cookingTimeLabel;
- (void) weightValueHasChanged:(id)sender;
@end
我的 xib 文件设置为有一个 RoastChickenViewController
因为它是文件的所有者类型,并且 weightSlider
已连接并且“valueChanged”操作连接到 weightValuHasChanged:
。
问题是,一旦我触摸滑块(模拟器或设备),我就会得到:
2010-08-21 20:26:07.688 CookIt1[26682:207] -[NSCFString weightValueHasChanged:]: unrecognized selector sent to instance 0x59215e0
2010-08-21 20:26:07.690 CookIt1[26682:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString weightValueHasChanged:]: unrecognized selector sent to instance 0x59215e0'
*** Call stack at first throw:
(
0 CoreFoundation 0x02395919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x024e35de objc_exception_throw + 47
2 CoreFoundation 0x0239742b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x02307116 ___forwarding___ + 966
4 CoreFoundation 0x02306cd2 _CF_forwarding_prep_0 + 50
5 UIKit 0x002b9e14 -[UIApplication sendAction:to:from:forEvent:] + 119
6 UIKit 0x003436c8 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x00345b4a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
8 UIKit 0x003c23ac -[UISlider beginTrackingWithTouch:withEvent:] + 731
一点历史记录,我实际上是直接使用子类化 UIView 来完成这项工作的。我已经成功地在从 UIView 转换为 UIViewController 时打破了它,我想这是实现这样的简单行为的更自然的方式。
是否有某种我可以应用的检查清单,因为显然我缺少一些东西。
I have a very simple subclass of UIViewController
:
@interface RoastChickenViewController : UIViewController {
IBOutlet UISlider *weightSlider;
}
@property (nonatomic,retain) UILabel *cookingTimeLabel;
- (void) weightValueHasChanged:(id)sender;
@end
My xib file is set to have a RoastChickenViewController
as it's File's owner type and the weightSlider
is connected and the 'valueChanged' action is connected to weightValuHasChanged:
.
Trouble is as soon as I touch the slider (simulator or device) I get:
2010-08-21 20:26:07.688 CookIt1[26682:207] -[NSCFString weightValueHasChanged:]: unrecognized selector sent to instance 0x59215e0
2010-08-21 20:26:07.690 CookIt1[26682:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString weightValueHasChanged:]: unrecognized selector sent to instance 0x59215e0'
*** Call stack at first throw:
(
0 CoreFoundation 0x02395919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x024e35de objc_exception_throw + 47
2 CoreFoundation 0x0239742b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x02307116 ___forwarding___ + 966
4 CoreFoundation 0x02306cd2 _CF_forwarding_prep_0 + 50
5 UIKit 0x002b9e14 -[UIApplication sendAction:to:from:forEvent:] + 119
6 UIKit 0x003436c8 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x00345b4a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
8 UIKit 0x003c23ac -[UISlider beginTrackingWithTouch:withEvent:] + 731
A little bit of history, I actually had this working using having subclassed UIView directly. I have managed to break it on converting in from a UIView to a UIViewController, which I guess is the more natural way to implement simple behavior like this.
Is there some sort of check list I can apply as there is obviously something I'm missing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来好像您正在对 NSCFString 调用weightValueHasChanged。这几乎肯定不是您想要的! IB 中的连接已损坏,或者您显式将weightValueHasChanged 发送到 NSCFString 的实例。
It seems as if you are calling weightValueHasChanged on an NSCFString. This is almost certainly not what you want! Either your connections in IB are broken or you are explicitly sending weightValueHasChanged to an instance of NSCFString.
当接收者对象由于某种原因被释放并且其在内存中的地址现在被其他对象占用时,通常会发生这种错误(当接收消息的对象的类型与预期完全不同时)。
因此,您需要检查控制器的内存管理是否一切正确。
This kind of error (when object that receives a message is of completely different type from expected) often occurs when the receiver object for some reason was deallocated and its address in memory now is occupied with some other object.
So you need to check if everything correct with memory management of your controller.