从 UISlider 实现 valueChanged 操作时出现无法识别的选择器错误

发布于 2024-09-15 05:52:18 字数 1897 浏览 9 评论 0原文

我有一个非常简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

∝单色的世界 2024-09-22 05:52:24

看起来好像您正在对 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.

糖果控 2024-09-22 05:52:20

当接收者对象由于某种原因被释放并且其在内存中的地址现在被其他对象占用时,通常会发生这种错误(当接收消息的对象的类型与预期完全不同时)。

因此,您需要检查控制器的内存管理是否一切正确。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文