开发者

Accessing parentViewController's variables

开发者 https://www.devze.com 2022-12-20 14:06 出处:网络
I want to all开发者_如何学JAVAow 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)

I want to all开发者_如何学JAVAow 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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号