0

我对 xcode 很陌生,对它了解不多。我正在制作一个应用程序,您在第一个视图中将文本输入到 textField 中,然后单击一个按钮,并将更改第二个视图中标签的文本。

这是代码。(小版本)首先查看代码。

    #import "SecondViewController.h"  
    - (IBAction)Settext:(id)sender;
    @property (weak, nonatomic) IBOutlet UITextField *textField;
    @implementation FirstViewController 

    - (IBAction)Settext:(id)sender {
    self.text = self.textField.text;
    self.label.text = self.text


    }
    @end
4

2 回答 2

0

你需要使用segues。这些让我困惑了一段时间,但它们确实不错。当你点击按钮时,你需要触发一个 segue(这只是意味着视图正在移动到另一个控制器)然后你像你所做的那样 #import 第二个视图控制器的 .h 。然后使用 -(void)prepareForSeuge 方法,如下所示

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{    
        // Get reference to the destination view controller
        YourViewController *vc = [segue destinationViewController];

        //This is where you would set the text from the second view controller to what you want
       vc.yourText = @"What ever you need it to be";
    }
}

您需要在第二个视图控制器中为 NSString 创建一个名为 yourText 的 @property

于 2014-07-09T19:52:07.590 回答
0

在第二个视图类中创建一个字符串属性。在调用第二个视图时设置字符串值。使用viewDidLoadsecovd 视图中的值。

于 2013-03-14T20:25:45.903 回答