如何将一个视图控制器中的字符串变量访问到另一个视图控制器 [英] How to Access String Variable in One View Controller to Another view Controller
问题描述
我是iphone开发的新手,现在我想访问所有视图控制器中的字符串变量,但我知道在委托方法中声明变量,但我无法访问它,请帮帮我.
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.
Mainviewcontroller-->Viewcontroller1_-->viewcontroller2-->viewcontroller3-->subwebview.
我创建了一个主视图控制器,子视图类是Viewcontroller1、viewcontroller2、viewcontroller3.而subwebview是所有三个viewcontroller(Viewcontroller1,Viewcontroller2,Viewcontroller3)的子类.
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).
现在我想从所有视图控制器(Viewcontroller1,Viewcontroller2,Viewcontroller3)访问subwebview中的字符串变量,我如何访问SUBWEBVIEW中的字符串变量.
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.
我正在使用 Rss 提要阅读器并检索数据.
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.
谢谢.
推荐答案
最简单的方法是传入对 parentViewController 的引用,然后您就可以通过该引用访问您的变量.不确定您使用的是什么类名,但类似这样:
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;
为其添加@property
和@synthesize
这篇关于如何将一个视图控制器中的字符串变量访问到另一个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!