Reputation: 153
I am writing a simple datepicker code for iphone but this one error is driving me crazy. Here are two use cases, one where it works and second where it doesn't:
working case: When I select a date from picker and create a UIButton and calls the "-(IBAction)showdate:(id)sender" with "touch up inside" event of this button. showdate is a simple method which right now shows an alert of selected date.
non-working case: When I call the same above mentioned method with "Value Changed" event of the picker I get following error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType showdate:]: unrecognized selector sent to instance
I have tried this with both Interface Builder as well as programmatically but getting similar results.
Could someone please tell me what am I missing here.
thanks,
Rols
Upvotes: 2
Views: 1749
Reputation: 12787
You are doing wrong you cant call the IBAction with datePicker like this. For calling a function on value change event of date picker you dont need any button, Do like this.
Use this in your viewDidLoad-
[self.datePicker addTarget:self
action:@selector(showdate:)
forControlEvents:UIControlEventValueChanged];
then write this function in your .m file.
-(void)showdate:(id)sender
{
//your code.
}
Upvotes: 2