SecondVCに 2 つのビュー コントローラーがあり、UITextFieldデータをUILabel最初の viewController にプッシュします。最初の ViewController は に埋め込まれていUINavigationControllerます。
prepareForSegue?
SecondVCに 2 つのビュー コントローラーがあり、UITextFieldデータをUILabel最初の viewController にプッシュします。最初の ViewController は に埋め込まれていUINavigationControllerます。
prepareForSegue?
簡単な方法の 1 つは、ブロック プロパティを使用することです。
を受け取る SecondVC でブロック プロパティを公開しますNSString。
@property (copy, nonatomic) void ^TextFieldBlock(NSString *textString);
prepareForSegue最初のビュー コントローラーでこのプロパティを設定しUILabel、ブロック内を更新します (保持サイクルの問題を回避するには、weakSelf を使用します)。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
__weak typeof(self)weakSelf = self;
[segue.destinationViewController setTextFieldBlock:^(NSString *textString) {
weakSelf.mainLabel.text = textString;
}];
}
次に、SecondVC でブロック プロパティを呼び出し、UITextField返されたときに のテキストを渡します。
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
[self TextFieldBlock](textField.text);
return YES;
}