当您使用代码创建模态视图 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/