Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello

can you please tell me how to pass value between two classes .As i know about java we pass in constructor .

Take a simple example i have one text field and button on click i want to pass text field text to second view ?

Differnt way to pass the values in object c. With example
Posted

1 solution

view controller class .h
@property (nonatomic, strong) IBOutlet UITextField *text1;

view controller class .m
@synthesize text1;
- (IBAction)passbutton:(id)sender
{
ViewController1 *vc1 = [[ViewController1 alloc]init];
NSString *text1value;
text1value = [text1 text];
vc1.text2value = text1value;
[self presentViewController:vc1 animated:YES completion:nil];
}

second - view controller1 class .h
@property (nonatomic, retain) IBOutlet UITextField *text2;
@property (nonatomic, retain) NSString *text2value;

view controller1 class .m
@synthesize text2,text2value;
(void)viewDidLoad
{
[super viewDidLoad];
text2.text = text2value;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900