Reputation: 41
i want to use one data string stored in extern string variable in one view controller, in the other view by calling that variable in second view controller. and want to print the variable's value in the text box present in second view controller on a button click of button present in it. please tell me how i can do that using objective-C?
please tell what to do in all the 4 files that are: ViewController.h, ViewController.m, SecondViewController.h and SecondViewController.m.
Upvotes: 0
Views: 718
Reputation: 1818
I think you need to pass one variable data into another view controller.
viewController.m
-(void)viewWillDisappear {
//pass value to secondViewController
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; // use your storyboard name
secondviewcontroller *vc = [storyboard instantiateViewControllerWithIdentifier:@"secondviewcontroller"];
vc.value2 = @"String here";
}
secondViewController.h
@property (nonatomic, retain) NSString *value2;
secondViewController.m
@implementation coachViewController
@synthesize value2;
-(IBAction)buttonPressed {
self.label.text = value2; //Declare value2 in .h file
}
Upvotes: 0
Reputation: 196
viewController.m
-(void)viewWillDisappear {
//pass value to secondViewController
secondViewController *vc=[[secondviewcontroller alloc]init];
vc.headStr=@"your string"; //same for array and dictionary
//Push code.........
}
//secondViewController.h
@property (strong, nonatomic) NSString *headStr;
secondViewController.m
-(void)ViewDidLoad
{
[super:ViewDidLoad];
Nslog("%@",self.headStr);
}
Upvotes: 1
Reputation: 780
if i see your comment on Shameerjans post i see that you dont know what your doing. Please do this tutorial from apple Start Developing iOS Apps
This is a cool jump in and covers very much functionality for displaying elements and using more controllers.
Upvotes: 0