Is it possible to declare anonymous implementations of things like Delegates in Objective-C. I think I have the terminology right, but here's a java example:
myClass.addListener(new FancyInterfaceListener({
void onListenerInterestingAction(Action a){
....interesting stuff here
}
});
So for example to handle an UIActionSheet call I have to declare another method in the same class, which seems a bit silly if I want to pass it data, because I'd have to store that data as a global variable. Here's an example of deleting something with a confirmation dialog asking you if your sure:
-(void)deleteItem:(int)indexToDelete{
UIActionSheet *confirm = [[UIActionSheet alloc] initWithTitle:@"Delete Item?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete" otherButtonTitles:nil];
[confirm showInView:self.view];
[confirm release];
}
and the UIActionSheetDelegate in the same class:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0){
[[Settings sharedSettings] removeItemAtIndex:/*need index variable here*/];
[drinksTable reloadData];
}
}
What I want to be able to do is declare it inline, just like I did in the java example at the top. Is this possible?