2013-02-12 53 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

相關問題