1

Code:

[[UIApplication sharedApplication] delegate];

Through this code how to pass data from one to another.

SeraZheng
  • 187
  • 8

3 Answers3

0

Basically there is only one instance of 'sharedApplication' (it is a singleton), which means that instances of view controllers that are independent of each other can still talk to the same data object. You can therefore write methods in your sharedApplication delegate which can effectively allow these two view controllers to communicate. For more information please see the Apple documentation.

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/

mcfisty
  • 187
  • 10
  • @AmirKhanKhan SO is not a code writing service. Try to write some code and come back when you have problems with it. – Fabio Berger Jan 15 '16 at 07:00
0

You can use the segue destination view controller for transfar data between controllers.Suppose you have one TextField in one View Controller and you want to pass the Textfield text to another viewController.Then use this it might be helpful.

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
TargetViewController *tvc; //Second view controller Object
tvc = [segue destinationViewController];
tvc.lonetxt = fname.text; //use properties of another view using . operator
tvc.ltwotxt = lname.text;
tvc.lthreetxt = age.text;
tvc.lfourtxt = college.text;
}
viratpuar
  • 524
  • 1
  • 5
  • 22
0

Try following:

Interface in Your AppDelegate:

@interface MyAppDelegate : NSObject  {
  NSString *myString;
}
@property (nonatomic, retain) NSString *myString;
...
@end

and in the .m file for the App Delegate you would write:

@implementation MyAppDelegate

@synthesize myString;
myString = some string;

@end

Then, in viewcontroller.m file you can fetch:

MyAppDelegate *appDelegate = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];
someString = appDelegate.myString;  //..to read
appDelegate.myString = some NSString;     //..to write
Ronak Chaniyara
  • 5,335
  • 3
  • 24
  • 51