views:

48

answers:

2

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 behaviour like this.

Is there some sort of check list I can apply as there is obviously something I'm missing.

+1  A: 

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.

ennuikiller
Also you're going to want to change `void` to `IBAction` so Interface Builder recognizes your function.
Alexsander Akers
IB recognizes the function just fine, you haven't need IBAction for a while now, but for completness I have tried that as well and it doesn't help.
Gareth Davis
@ennuikiller thanks yes it seems to be a bit random, after just trying the IBAction thing again I noticed that it was attempting to send the message to an instance of NSDict!
Gareth Davis
glad to have helped!
ennuikiller
The problem may be that your RoastChickenViewController was deallocated for some reason and its address now occupied with some other object.
Vladimir
@Vladimir Bingo! give that man a prize..or more likely give him the accepted answer and a upvote if he wants to put that in a full answer.
Gareth Davis
+1  A: 

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.

Vladimir
Thanks. stay tuned for another question on why my memory management is broken.
Gareth Davis