访问parentViewController的变量
我想允许推送设置parentViewController 的实例变量。例如,VC1(父级)有一堆文本字段以及其他由 VC2(子级)填充的文本字段。 VC2 由 VC1 压入堆栈。我尝试过像 parentViewController.myString = "foo";
但由于parentViewController 是 UIViewController,我无法编辑 myString 字段。
基本上,我的问题是“如何访问父级的实例变量?”
编辑:我在这里尝试了解决方案: 设置属性值父视图控制器类来自子视图控制器?但它充满了语法错误。
I want to allow a pushed to set parentViewController's instance variables. For instance, VC1 (the parent) has a bunch of textfields and what not which are filled from VC2 (the child). VC2 is pushed onto the stack by VC1. I've tried doing like parentViewController.myString = "foo";
however since parentViewController is a UIViewController, I can't edit the myString field.
Basically, my question is "How can I access the parent's instance variables?"
Edit: I tried the solution here: Setting property value of parent viewcontroller class from child viewcontroller? but it is chocked full of syntax errors.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
拥有父视图控制器子类
UIViewController
(例如ParentViewController
),实现您想要操作的实例变量的所有属性,并将变量设置为((ParentViewController * )parentViewController).myString = @"foo";
。例如
和
Have the parent view controller subclass
UIViewController
(e.g.ParentViewController
), implement all the properties for instance variables you wish to manipulate, and set the variables as((ParentViewController *)parentViewController).myString = @"foo";
.E.g.
and