Unrecognized selector error when implementing a valueChanged action from a UISlider

﹥>﹥吖頭↗ 提交于 2019-12-11 07:35:19

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3538589/unrecognized-selector-error-when-implementing-a-valuechanged-action-from-a-uisli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!