UIViewController的双向关系(Two way relation for UIViewController)

编程入门 行业动态 更新时间:2024-10-26 18:27:44
UIViewController的双向关系(Two way relation for UIViewController)

我有一个容器视图控制器说ContainerViewController和另一个UIViewController(PhotoViewcController)我将其添加为ContainerViewController中的childviewcontroller。 这条消息从ContainerViewController转发到PhotoViewcController。 但是,如何在父子视图控制器中使用双向关系? 以便将消息从PhotoViewcController传递到ContainerViewController。

I have a container view controller say ContainerViewController and another UIViewController(PhotoViewcController) which i am adding as a childviewcontroller in ContainerViewController. So that message is forwarded from ContainerViewController to PhotoViewcController. But how can i use the two way relation in the parent child view controllers? so that message is passed form PhotoViewcController to ContainerViewController.

最满意答案

像这样在子类中创建一个属性

@property (assign) id pDelegate;

并合成它,当你转到子视图控制器时,在push / present之前将委托设置为self

childController.pDelegate = self;

现在,当您要发送消息时,请执行此操作

if([self.pDelegate respndsToSelector:@selector(popedBackFromChild:)]) { [self.pDelegate popedBackFromChild:<some object>]; }

告诉我你是否需要进一步解释

make a property in child class like this

@property (assign) id pDelegate;

and synthesize it, and when you go to child view controller, set the delegate as self before push/present as

childController.pDelegate = self;

now when you want to send the message, do this

if([self.pDelegate respndsToSelector:@selector(popedBackFromChild:)]) { [self.pDelegate popedBackFromChild:<some object>]; }

tell me if you need further explanation

更多推荐

本文发布于:2023-08-01 19:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1364800.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:双向   关系   UIViewController   relation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!