0

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.

1
  • The CurrencyViewController should have the instance of InputViewController. Then you can access that variable Commented Feb 12, 2013 at 8:40

1 Answer 1

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.
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks ! I already tried it. Still not working. Used protocols, object instance. no joy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.