【问题标题】:How to make textFields from different classes equal the same text?如何使来自不同类的文本字段等于相同的文本?
【发布时间】:2016-03-09 16:07:46
【问题描述】:

我是 iOS 开发的初学者。在我的FirstViewController 中,我有两个文本字段,我使用UITextFieldDelegate 使这两个等于相同的内容。在我的SecondViewController 中,我有另一个文本字段,我需要使它与FirstViewController 中的文本字段具有相同的内容。

FirstViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];

    _FirstTextField.delegate = self;
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    SecondTextField.text = textField.text;

【问题讨论】:

    标签: ios objective-c


    【解决方案1】:

    很简单 将 FirstViewController 中文本字段的文本传递给 SecondViewController 使用字符串并将传递的字符串分配给 SecondViewController 的文本字段

    为了传递字符串,你可以有很多选择

    1) 使用转场

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
    if ([[segue identifier] isEqualToString:@"secondViewSegue"]) {
        SecondViewController *objVC = [segue destinationViewController];
        objVC.strText = textfeld.text;
    }
    

    2) 推送时直接传递数据

    SecondViewController *objVC = [[SecondViewController alloc] initWithNib:@"SecondViewController" bundle:nil];
    objVC.strText = textfield.text;
    [self pushViewController:objVC animated:YES];
    

    【讨论】:

      【解决方案2】:

      您可以将变量传递给 Segue 中的第二个 View Controller。

      Passing variables between view controllers

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多