开发者

How do I assign a delegate to multiple classes

开发者 https://www.devze.com 2023-03-22 16:51 出处:网络
I have a custom delegate, and I want 2 classes to respond to it\'s events.How can I assign it to both 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

精彩评论

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