How to send string value from secondView to mainView with use popover segue?

非 Y 不嫁゛ 提交于 2019-12-08 08:02:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!