我有一個使用UITextFields的tableview來構建表單。然後我在工具欄中有一個按鈕,它啓動一個模式視圖控制器來選擇一些數據,然後傳回到tableview。但是,選中的新數據不會使用textField.text = valueReturnedFromModal語法刷新到UITextField中。有什麼我失蹤?如何在從模式中選擇數據後刷新UITableViewCell中的UITextField
我看到數據正在從模態中正確返回,所以這不是問題。我只是無法迫使UITextField刷新新數據。我已經嘗試在tableview上強制重載數據。
因此,從模式的看法,下面是數據傳遞迴代碼:
- (void)doneAccountSelection:(id)sender
{
[delegate didSelectAccount:currentAccount];
[self dismissModalViewControllerAnimated:YES];
}
,這裏是在代表實際的方法:
- (void)didSelectAccount:(SFAccount *)selectedAccount
{
//Ensure a valid deal exists for the account to be attached to
[self createDealObjectIfNeeded];
//Set the deal account
[self.deal setAccount:selectedAccount];
//Refresh the text fields
//Tag 3: Account Name field
UITextField *acct_name = (UITextField *) [self.view viewWithTag:3];
[acct_name setText:self.deal.account.field_acct_name_value];
//Tag 4: Account City field
UITextField *acct_city = (UITextField *) [self.view viewWithTag:4];
[acct_city setText:self.deal.account.field_acct_city_value];
//Save the context changes. A new deal gets created above if one does not exist.
if ([self saveModel]) NSLog(@"Acct object created, attached to deal successfully!");
[self.tableView reloadData];
}
如果我正確理解你的答案,那麼textfield不會啓動模態視圖,所以這將無法正常工作。模式視圖將數據返回到tableviewcontroller中的委託方法,並且在該函數中,我需要更新文本字段中的文本。 – 2012-03-13 17:53:54