2016-07-20 138 views
6

正如標題所述,我在UITableViewCell中有UITextFieldUITableViewCell中的UITextField在插入後成爲第一個響應者

我的tableView列出一個數組項稱爲tallies: [String]

我插入按鈕水龍頭一個新條目,並在新的小區動畫。我想titleTextFieldbecomeFirstResponder一旦rowAnimation已完成,但到目前爲止無法使其工作。行插入後

CATransaction.begin() 
CATransaction.setCompletionBlock { 
    let cell = self.tableView(self.tableView, cellForRowAtIndexPath: self.editingIndexPath!) as! TallyCell 
    cell.titleTextField.hidden = false 
    cell.titleTextField.becomeFirstResponder() 
} 

tableView.beginUpdates() 
tallies.append("Example") 
tableView.insertRowsAtIndexPaths([editingIndexPath!], withRowAnimation: .Left) 
tableView.endUpdates() 

CATransaction.commit() 

回答

0

製作文本字段第一響應:

新的行動畫的完美,但titleTextField不會becomeFirstResponder

這裏就是我試過。

+0

對不起,我應該說,它似乎停止行動畫,如果我 – Leon

+0

後直接把它刪除CTTransaction和做類似[的tableView insertRowsAtIndexPaths:@ [indexPath] withRowAnimation: UITableViewRowAnimationLeft]; [cell.textLabel becomeFirstResponder]; – jagdish

+1

也試過了。沒有運氣 – Leon

0

試試這個代碼

CATransaction.begin() 
CATransaction.setCompletionBlock { 
    let cell = self.tableView(self.tableView, cellForRowAtIndexPath: self.editingIndexPath!) as! TallyCell 
    cell.titleTextField.hidden = false 
} 

tableView.beginUpdates() 
tallies.append("Example") 
tableView.insertRowsAtIndexPaths([editingIndexPath!], withRowAnimation: .Left) 
tableView.endUpdates() 
CATransaction.commit() 
let cellNew = self.tableView(self.tableView, cellForRowAtIndexPath:self.editingIndexPath!) as! TallyCell 
cellNew.titleTextField.becomeFirstResponder() 
+0

這是行不通的,因爲'cell'在塊 – Leon

+0

內定義,但是您需要在CATransaction.commit() –

+0

檢查編輯答案 –

相關問題