Search code examples
iphoneobjective-cuislider

Unrecognized selector error when implementing a valueChanged action from a UISlider


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.


Solution

  • 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.