简体   繁体   中英

Difficulty implementing delegate methods in an objective-c project

I have a table view which I am using as a form. The first cell has an editable text field. The second cell, when clicked, loads a semi modal date picker. I used this: http://reednj.tumblr.com/post/1346445326/ios-semi-modal-date-picker-for-iphone

Anyway, I've defined my datepicker and set its delegate inside the tableviewcontroller like so:

TDDatePickerController* datePickerView = [[TDDatePickerController alloc] 
                                              initWithNibName:@"TDDatePickerController" 
                                              bundle:nil];
    [datePickerView setDelegate:self];
    [self presentSemiModalViewController:datePickerView];

Now the methods to handle the button clicks are defined as

-(void)datePickerSetDate:(TDDatePickerController*)viewController;
-(void)datePickerClearDate:(TDDatePickerController*)viewController;
-(void)datePickerCancel:(TDDatePickerController*)viewController;

So when the cancel button is pressed I would like the semi-modal date picker to be dismissed, So I've got:

-(void)datePickerCancel:(TDDatePickerController*)viewController{
[self dismissSemiModalViewController:viewController];
}

But this makes the app crash with the error

-[__NSCFType cancelDateEdit:]: unrecognized selector sent to instance 0xe738c00

2012-09-18 10:23:47.254 JRPBaseCamp[7612:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType cancelDateEdit:]: unrecognized selector sent to instance 0xe738c00'

So I looked up the cancelDateEdit method in TDDatePickerController:

-(IBAction)cancelDateEdit:(id)sender {
if([self.delegate respondsToSelector:@selector(datePickerCancel:)]) {
    [self.delegate datePickerCancel:self];
} 
}

What am I doing wrong? It must be something obvious that I'm overlooking. Any help is much appreciated, I'm fairly new to iOS and the whole concept of delegates is really confusing me. Thanks!

The unrecognized selector sent means nothing is responding to cancelDateEdit: selector. You can use the debugger to search what kind of object is 0xe738c00 and then look for the appropriate selector there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM