क्या उद्देश्य-सी में प्रतिनिधियों जैसे गुमनाम कार्यान्वयन की घोषणा करना संभव है। मुझे लगता है कि मैं शब्दावली का अधिकार है, लेकिन यहाँ एक जावा उदाहरण है:बेनामी प्रतिनिधि कार्यान्वयन?
myClass.addListener(new FancyInterfaceListener({
void onListenerInterestingAction(Action a){
....interesting stuff here
}
});
इसलिए उदाहरण के एक UIActionSheet कॉल मैं एक ही कक्षा में एक और तरीका है, जो थोड़ा पागल लगता है कि अगर मैं पास करना चाहते हैं की घोषणा करने के लिए है संभाल करने के लिए यह डेटा, क्योंकि मुझे उस डेटा को वैश्विक चर के रूप में स्टोर करना होगा। यहाँ अगर आप पूछ एक पुष्टिकरण संवाद के साथ कुछ को हटाने का एक उदाहरण है अपने यकीन है कि:
-(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];
}
और एक ही कक्षा में UIActionSheetDelegate:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0){
[[Settings sharedSettings] removeItemAtIndex:/*need index variable here*/];
[drinksTable reloadData];
}
}
यह इनलाइन घोषित मैं क्या करने में सक्षम होना चाहता हूँ , जैसे मैंने शीर्ष पर जावा उदाहरण में किया था। क्या यह संभव है?
मैं इस तरह की स्थितियों के लिए एक सकारात्मक समाधान लिखता हूं [यहां] (https://github.com/GojaN/AnonymusDelegate)। ध्यान रखें कि यह अवधारणा का सबूत है। –
हाँ, आप इसे तृतीय-पक्ष पुस्तकालयों के साथ कर सकते हैं, मेरा पूरा उत्तर यहां पढ़ें: http://stackoverflow.com/a/33096839/440168 – k06a