如何使用popover segue从secondView将字符串值发送到mainView? [英] How to send string value from secondView to mainView with use popover segue?

查看:66
本文介绍了如何使用popover segue从secondView将字符串值发送到mainView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将字符串值从secondView发送到mainView,但是我单击确定"按钮,使用此代码[self dismissViewControllerAnimated:YES completion:nil];,然后准备segue无法正常工作.当我想单击确定"按钮时,我将textfield值发送到mainView控制器.

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.

感谢回复.

推荐答案

在主视图控制器(包含标签)头文件中,声明标签的出口:

In your Main View Controller (That contains the label) header file declare the outlet for the label:

@property (nonatomic, weak) IBOutlet UILabel *nameLabel;

在您的SettingsViewController.m中,导入您的ViewController.h.并更改下面的OK按钮l.ke>

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];
}

由于OP正在使用UINavigationController并推送segues进行导航,因此该方法应更改为:

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];
}

这篇关于如何使用popover segue从secondView将字符串值发送到mainView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆