2013-02-12 50 views
0

我有两个视图控制器文件,分别是InputViewControllerCurrencyViewController。我想访问CurrencyView中的InputView中声明的变量。它是在空应用程序项目中设计的。如何从ios中的另一个nib文件访问变量

+0

CurrencyViewController应该有InputViewController的实例。然后你可以访问变量 – 2013-02-12 08:40:06

回答

2
You can declare the variable globally in AppDelegate & then can access in both viewController. 
The changes made in the variable will reflect in both controllers. 
Make the variable as a property of AppDelegate.h class 
eg. @property (strong, nonatomic) NSString *Var; 
& synthesize it in AppDelegate.m 
@synthesize Var; 

declare "AppDelegate * appDelegate" in both Controllers.h & then in controller.m in viewDidLoad write appDelegate=[[UIApplication sharedApplication]delegate]; 

now the variable can accessible using appDelegate.var anywhere in your code of both ViewController & changes are also reflected in both. 
Hope this will work more efficiently for your need. 
+0

谢谢!我已经尝试过了。还是行不通。使用的协议,对象实例。没有快乐 – BudHawk 2013-02-13 04:59:32

相关问题