访问parentViewController的变量

发布于 2024-08-21 13:06:20 字数 441 浏览 5 评论 0原文

我想允许推送设置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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对你的占有欲 2024-08-28 13:06:20

拥有父视图控制器子类UIViewController(例如ParentViewController),实现您想要操作的实例变量的所有属性,并将变量设置为((ParentViewController * )parentViewController).myString = @"foo";

例如

@interface ParentViewController : UIViewController {
    NSString *myString;
}
@property (nonatomic, retain) NSString *myString;
@end

@implementation ParentViewController

@synthesize myString;

@end

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.

@interface ParentViewController : UIViewController {
    NSString *myString;
}
@property (nonatomic, retain) NSString *myString;
@end

and

@implementation ParentViewController

@synthesize myString;

@end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文