Help - Search - Members - Calendar
Full Version: Creating Callbacks ("messages") with SEL
InsanelyMac Forum > Apple World > Gadgets and Handheld Devices > iPhone
Tsuichi5
I'm having a problem creating a class that has an assigned callback with a (SEL) object.

Basically, I'm creating a custom UIPicker object that contains the array of objects to select from, and use a callback to identify when the selector item has been chosen, and the dialog box is to be removed from the screen.

What I'm trying to do is:

CODE
- (void)loadView {
NSArray *array = [NSArray initWithObjects: @"Test 1", @"Test 2", nil];
CustomPicker *picker = [[CustomPicker alloc] initWithArray:array];

[picker actionSelected:@selector(selectedFirstPicker:)];
}

- (void)selectedFirstPicker:(id)sender {
NSLog(@"Picker selected! Congradulations.\n");
}


I can *set* the object inside my interface by saying:

CODE
@interface CustomPicker : UIPickerViewDelegate {
SEL onClick;
}


And when I try calling the "onClick" object, it blows up in my face:

CODE
- (void)actionSelected:(SEL)object {
onClick = object;
}

- (void)callClick {
[self performSelector:onClick withObject:self];
}


But the SDK doesn't like that, it dies on objc_send.

Does anyone have a working example of this? Or can anyone tell me what I'm doing wrong? Maybe I need to create the "onClick" object as a property, and synthesize it in the class?

I looked over the docs from Apple and they're technically very vague. Not sure what I am doing wrong.
Tsuichi5
Further research shows:

[self performSelector:onClick];

Throws a huge exception.

[self.parentViewController performSelector:onClick];

Does nothing.

Also, [respondsToSelector:doneCallback] returns false.

PLEASE. I *HOPE* someone can help. I've asked several questions, and they receive absolutely no responses. I hope this isn't some strange topic that no one's ever used.
Tsuichi5
Never mind, all, figured it out.
Aatif
how u figured it out? I also want to use some custom picker to enable user to select from a list of items ...
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.