考慮到代理方法 textFieldDidEndEditing 無法監聽到 textField 實時的內容變化,若要實現實時監聽,建議注冊通知來監聽 UITextField 的實時改變。直接上代碼:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(infoAction) name:UITextFieldTextDidChangeNotification object:nil];
- (void)infoAction
{
NSIndexPath *index = [NSIndexPath indexPathForRow:0 inSection:1];
OrderConfirmInfoTableViewCell *cell = (OrderConfirmInfoTableViewCell *)[_tableView cellForRowAtIndexPath:index];
_phoneStr = cell.phoneField.text;
_addrStr = cell.addressField.text;
}
在 infoAction 裡,就可以把監聽的 textField 的值變化實時賦值給另一個對象。