开发者

How do I assign a delegate to multiple classes

I have a custom delegate, and I want 2 classes to respond to it's events. How can I assign it to both classes.

ie:

viewController.开发者_JS百科delegate = firstClass && self;


You could create a third class that handles the event by delegating it to the two classes.

viewController.delegate = delegatingClass;

...and in the object referred to as delegatingClass, implement the method that you're concerned about by calling that same method on the two classes you want to handle the event. For example:

void handleEvent( Event event ) {
    firstClass.handleEvent( event );
    otherClass.handleEvent( event );
}


If you need an event to be called multiple places you should use NSNotificationCenter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜