Creating an Object to Work as a Delegate - Goal C

My question is actually simple, how do I create an object to work as a delegate, instead of including delegate methods in it?

For example, I have x functionality that requires delegate methods, and they are currently configured to use self as a delegate. I would like to put these methods in my own object so that delegate methods can be called and executed if the view has ended.

What is the best way?

+3
source share
2 answers

, NSXMLParser - , , ... ?

, . , MyXMLParserDelegate - . , , NSXMLParser, .

Interface Builder, XIB , MyXMLParserDelegate, NSXMLParser object delegate .

, :

MyXMLParserDelegate * myDelegate = [[MyXMLParserDelegate alloc] init];
[someXMLParser setDelegate:myDelegate];

, , ivar MyXMLParserDelegate viewController :

// in your @interface block:
{
    ...
    MyXMLParserDelegate * myDelegate;
}

// in your init method:
myDelegate = [[MyXMLParserDelegate alloc] init];

// in your awakeFromNib method (or anywhere else it seems appropriate):
[someXMLParser setDelegate:myDelegate];

// in your dealloc method:
[myDelegate release];
+2

, , , : Objective-C

+1

Source: https://habr.com/ru/post/1729572/


All Articles