问题
i want to send string value from secondView
to mainView
but I click OK button use this code [self dismissViewControllerAnimated:YES completion:nil];
and then prepare segue not working. When I want to click OK button, I send in textfield
value to mainView
controller.
Thanks in replies.
回答1:
In your Main View Controller (That contains the label) header file declare the outlet for the label:
@property (nonatomic, weak) IBOutlet UILabel *nameLabel;
In Your SettingsViewController.m
import your ViewController.h
. And change the OK
button l.ke below>
- (IBAction)goBack:(id)sender
{
ViewController *vCtrl = (ViewController *)self.presentingViewController;
vCtrl.nameLabel.text = yourTextField.text;
[self dismissViewControllerAnimated:YES completion:nil];
}
EDIT:
As OP is using UINavigationController
and push segues for navigating, the method should be changed to:
- (IBAction)goBack:(id)sender
{
ViewController *vCtrl = (ViewController *)[[(UINavigationController *)self.presentingViewController viewControllers] lastObject];
vCtrl.nameLabel.text = yourTextField.text;
[self dismissViewControllerAnimated:YES completion:nil];
}
来源:https://stackoverflow.com/questions/27874673/how-to-send-string-value-from-secondview-to-mainview-with-use-popover-segue