IOS/objective-C : Set property in presenting view controller

标签 ios uipresentingcontroller

当您使用代码创建模态视图 Controller 时,模态 Controller 能够访问呈现 Controller 。

请阅读以下内容。这就是问题的关键。我不想使用委托(delegate)。

根据 Apple doc s:

当您使用 present(_:animated:completion:) 方法以模态方式(显式或隐式)呈现 View Controller 时,呈现的 View Controller 会将此属性设置为呈现它的 View Controller 。

我想设置呈现 View Controller 的属性值。但是,我不会在代码中创建 VC。我使用按钮的转场。

这会产生错误:在 UIViewController 类型的对象上找不到属性 afterAdd:

   self.presentingViewController.afterAdd = YES;

其中属性 afterAdd 设置如下:

@property (nonatomic) BOOL afterAdd;

当链接是通过类似于上面的 Storyboard并且不涉及使用委托(delegate)方法时,是否有任何方法可以在呈现 View Controller 中设置属性的值?

最佳答案

您应该将 self.presentingViewController 转换为您的真实 View Controller 类。像这样,只需将 MyCustomViewController 替换为您的真实 Controller 名称:((MyCustomViewController *)self.presentingViewController).afterAdd = YES;

关于IOS/objective-C : Set property in presenting view controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40688192/

相关文章:

ios - 当使用大量输入调用时,Swift 中的递归函数会崩溃

ios - 应用程序在模拟器上的显示与 Storyboard上的不同

ios - 为什么我点击 UISwitch ,它不起作用?

iOS - 关闭在其 View 之外触摸的呈现 View Controller

iOS 新接触式 Swift 中的 Segue

iphone - 如何创建自动启动 iTunes 的 App Store 链接?

javascript - React Native 31,New Appdelegate.m 没有要更改的本地主机 : Network Request Failed