Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
474 views
in Technique[技术] by (71.8m points)

iphone - How to Access String Variable in One View Controller to Another view Controller

I am new to iphone development, Now i want to access the string variable in all the view controller, but i know to declare the variables in delegate method, but i cant access it, please help me out.

Mainviewcontroller-->Viewcontroller1_-->viewcontroller2-->viewcontroller3-->subwebview.

i have created one main view controller and the subview class are Viewcontroller1,viewcontroller2,viewcontroller3. And the subwebview is the subclass of all the three viewcontrollers(Viewcontroller1,Viewcontroller2,Viewcontroller3).

Now i want to access the string variables in subwebview from the all viewcontrollers(Viewcontroller1,Viewcontroller2,Viewcontroller3), How can i access the string variables in SUBWEBVIEW.

I am using Rss feed reader and retrieved the datas.

i have declared all the view controllers in my string variables like,

 NSString * currentElement;
 NSMutableString * currentTitle, * currentDate, * currentSummary, * currentLink;

i am stuck here. and i am not able to proceed.please help me out.

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The easiest is to just pass in a reference to the parentViewController and then you can access your variables through that reference. Not sure what class names you are using but something like this:

MyChildController *tmpViewController = [[MyChildController alloc] initWithNibName:@"ChildView" bundle:nil];
tmpViewController.myParentController = self;

This of course requires you to create a property in the child controller for the parent one:

ParentController *myParentController;

Add a @property and @synthesize for it as well


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...