如何在 Objective-C 中设置拥有视图的委托?
我有一个带有导航控制器的 parentViewController
。
我在导航控制器上推送一个视图。现在我可以轻松地将其委托设置为 self (以使其指向我的parentViewController ),但是从子视图中我将把下一个和下一个视图推送到导航控制器上。现在我希望最后一个视图也将其委托指向父视图。
例如
parentWindowController (navigationController)
- firstViewController -->第二个ViewController --> ThirdViewController
是否可以在初始化时将 thirdViewController 的委托设置为 parentWindowController ?
第三个视图是在第二个视图中创建的,因此我无法在一开始就设置它。
我想知道如何引用parentWindow。
这可能是错误的方法,请告诉我是否可以更容易/更好地完成?
I've got a parentViewController
with a navigation controller.
I push a view on the navigation controller. Now I can easily set its delegate to self (to make it point to my parentViewController
), however from the child view I will push the next and the next view onto the navigationcontroller. Now I want the last view also to have its delegate point to the parent view.
e.g.
parentWindowController (navigationController)
- firstViewController --> secondViewController --> thirdViewController
Is it possible to set the delegate of the thirdViewController to the parentWindowController from within its initialization?
The third view is created in the second view therefore I couldn't set this in the beginning.
I wonder how I can reference the parentWindow.
It might be the wrong approach, please let me know if it can be done easier/better?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过在parentViewController 中为firstViewController 分配委托解决了这个问题。
现在,当我创建第二个视图控制器时,我传递这个委托。当我创建第三个视图控制器时,我可以将委托设置为最初传递的委托。这有效。
但我仍然很好奇是否可以直接从 ThirdViewController 中执行此操作而不通过它。
I solved the problem by assigning the delegate for firstViewController within the parentViewController.
Now when I create the second view controller I pass this delegate on. When I create the third view controller I can set the delegate to the initially passed through delegate. This works.
I am still curious however if it was possible to do this directly from within the ThirdViewController without passing it through.