BudHawk
BudHawk

Reputation: 1

how to access a variable from another nib file in ios

I have two view controller files which is InputViewController and CurrencyViewController. I want to access the variable declared in InputView inside CurrencyView. It is designed in Empty Application Project.

Upvotes: 0

Views: 116

Answers (1)

Heena Mulla
Heena Mulla

Reputation: 196

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.

Upvotes: 2

Related Questions