I have created two view controllers (VC) in story board by drag and drop. I have added a button in first VC and a label in the second VC. For the Button Click in 1st VC I want to change the label text in the 2nd VC.
How can i do it?
I have created two view controllers (VC) in story board by drag and drop. I have added a button in first VC and a label in the second VC. For the Button Click in 1st VC I want to change the label text in the 2nd VC.
How can i do it?
Either you can use notification or simply create the property of label and access it in firstVC using object of second VC and change its value or simple use sendAction on click of the button in first VC to change the label in second VC refer following code
[[UIApplication sharedApplication] sendAction:@selector(yourMethod) to:nil from:self forEvent:nil];
and implement yourMethod in second VC and change its label.
I recommend, to do the viewcontroller change with segue. You just add a segue from the 1st viewcontroller to the 2nd, name it eg: "ToSecoundViewControllerSegue". On the button click event you call the performSegueWithIdentifier(name: "ToSecoundViewControllerSegue"...) method. Then in the first viewcontroller you override the prepareForSegue(...) method. In that method you can access your secound viewcontroller with the
(SecoundViewController*) secoundVC = (SecoundViewController) segue.destinationViewController
property. You cast this to SecoundViewController type and then you can easily access the label on the secound VC like:
secoundVC.textLabel.text = "this text will be shown on the screen"
cheers, ask for more code if you need