gpt4 book ai didi

cocoa-touch - 如何访问 super View Controller ?

转载 作者:行者123 更新时间:2023-12-02 07:42:34 25 4
gpt4 key购买 nike

我有一个问题,我会尝试解释这个问题:

  1. 我有一个主要的UIViewController(全屏)
  2. 我有一个辅助 UIViewController (setbounds)
  3. 我使用以下方法将辅助 View 添加到我的 mainView 中:

    [mainController.view addSubview:secondaryController.view];   
  4. 我创建了第三个 Controller :modalController,我将其添加到我的辅助 Controller 中,如下所示:

    [secondaryController presentModalViewController:modalController animated:YES];
  5. 我根据 modelController 内部的一些事件进行微积分。

  6. 我可以使用以下方式将消息从我的 modalController 发送到我的 secondaryController:

    [[self parentViewController]  performSelector : @selector(myMethodInSecondaryController:) withObject : myObject afterDelay : .5];

    注意:“self”对应于modalController

  7. 我需要将“myObject”传递给我的 mainController,但我无法从 secondaryController 引用我的 mainController。我试过这个:

    [[self parentViewController] performSelector : @selector(myMethodInMainController:) withObject:myObject afterDelay : .5];

    注意:“self”对应于secondaryController

    但它不起作用,我可以使用以下方式访问我的 mainController 的 View :self.view.superview

    注意:“self”是我的secondaryController

但对其 Controller 没有。

最佳答案

在您的辅助 Controller 中,尝试

id mainViewController = [self.view.superview nextResponder];

并检查这是否是您正在寻找的 View Controller 。

Apple 的 -[UIResponder nextResponder] 文档:

UIView implements this method by returning the UIViewController object that manages it (if it has one) or its superview (if it doesn’t)

关于cocoa-touch - 如何访问 super View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1034106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com