My question is simple actually, how do I create an object to act as a delegate, instead of including the delegate methods in my view?
For example, I have x functionality that requires delegate methods, and they’re currently setup to use self as the delegate. I’d like to put those methods in their own object so that the delegate methods can be called and do stuff if the view has ended.
What’s the best way?
You can specify another custom class to handle the delegate methods, if you wish. Simply create a class, call it
MyXMLParserDelegateor something similar. Then, all you have to do is tell yourNSXMLParserobject that it should use an instance of your class as its delegate.If you are using Interface Builder, add a new object to the XIB file, set its class to
MyXMLParserDelegate, and then drag a connection from yourNSXMLParserobject’sdelegateselector to the new object.If you are doing it programmatically, the basic operation looks like this:
Keep in mind, however, that delegates are not retained, so in order to do this without leaking memory, you should add an ivar of type
MyXMLParserDelegateto your viewController class, and then do the following: