问题描述
我想将字符串值从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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!