如何在一个视图控制器中访问字符串变量到另一个视图控制器 [英] How to Access String Variable in One View Controller to Another view Controller

查看:90
本文介绍了如何在一个视图控制器中访问字符串变量到另一个视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是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.

我创建了一个主视图controller和subview类是Viewcontroller1,viewcontroller2,viewcontroller3。 subwebview是所有三个viewcontrollers(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).

现在我想从所有viewcontrollers访问子网站中的字符串变量(Viewcontroller1 ,Viewcontroller2,Viewcontroller3),如何访问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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆