我有一些單元格帶有文本字段和其他標籤。基本上,在用戶使用鍵盤輸入數據後,他們可以導航到另一個文本框(通過各種方法),然後我們將他們希望去的textField保存在一個指針中,然後設置第一個響應者觸發文本字段的didEndEditing方法。在didEndEditing中,我調用刷新方法重新載入tableData以更新各種標籤,然後嘗試再次將setFirstResponder設置爲我存儲的文本字段。tableView reloadData丟失文本字段焦點
最終的結果是鍵盤停留在屏幕上,但文本框並未獲得焦點。但是,如果你再試一次,它會第二次運作...
這是一些代碼。請記住,很多已經被刪除,處理計算和日誌等我只加了與這個問題有關的東西。
編輯另外,我知道我提到我正在使用箭頭按鈕導航..如果您不使用箭頭按鈕,問題也在這裏。您必須兩次手動按(或單擊)一個文本字段才能在離開另一個文本字段後獲得焦點。
//user presses an arrow button to enter textfield
//logic is done here to find what the next textfield would be
_nextTextFieldSelection = (UITextField *)[[_tableView cellForRowAtIndexPath:destinationIndexPath] viewWithTag:newTag];
[_nextTextFieldSelection becomeFirstResponder];
- (void)textFieldDidEndEditing:(UITextField *)textField
{
//some stuff for calculations
[self refreshScreen]
}
- (void)refreshScreen
{
[_tableView reloadData];
//set tables values
[_nextTextFieldSelection becomeFirstResponder];
}
«很多已被刪除,處理計算和日誌等我只增加了與這個問題有關的東西»我可以得到一個AMEN! – 2013-02-27 19:09:40
如果在重新加載表視圖之後它是不同的文本字段,我不會感到驚訝。嘗試再次通過'[[_tableView cellForRowAtIndexPath:destinationIndexPath] viewWithTag:newTag];''''''''''''''''''''''''後面的'reloadData',看看它是否仍然與'_nextTextFieldSelection'是同一個對象。 – 2013-02-27 19:13:26
這很有道理,我會試試看。 – JMD 2013-02-27 19:15:03