2012-12-06 46 views

回答

1

一個簡單的方法是使用塊屬性。

揭露其採用NSString在SecondVC塊屬性:

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