开发者

Create a UIView Subclass that calls a delegate function whenever it's parent viewController appears?

开发者 https://www.devze.com 2022-12-23 02:08 出处:网络
EDIT 2: I now think the best soluton is to create ListeningView.h that just includes a ListeningView protocol, instead of subclassing ListeningView (since we can\'t do multiple inheritance in Obj-C).

EDIT 2: I now think the best soluton is to create ListeningView.h that just includes a ListeningView protocol, instead of subclassing ListeningView (since we can't do multiple inheritance in Obj-C). Then, you still need ListeningViewController as well.

EDIT: Ok, I figured out what the approved idiom is here. I should subclass UIViewController to create ResponderViewController, which will loop through its subviews for ResponderViews when it appears/disappears. Then, any viewController that has responderViews should inherit from ResponderViewController.

=======

UIViewControllers have viewWillAppear, viewDidDisappear, etc. delegate methods.

I would like to create a UIView subclass that can be added to a viewController's view, and when that UIViewController apears or disappears, a delegate function is called.

I could easily do this by putting function calls in the UIViewController viewWillAppear/viewWillDisappear delegate functions, but how can I encapsul开发者_Python百科ate this behavior in the UIView?


I wouldn't do that if I were you. All that sort of behavior should not be controlled by a view; that's just was controllers are for.

0

精彩评论

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

关注公众号