2016-07-20 9 views
6

タイトルが示すように、UITableViewCellの中にUITextFieldがあります。UITableViewCellのUITextFieldは、挿入後にfirstFirstResponderになります

私のtableViewがtallies: [String]

と呼ばれる配列のアイテムIは、ボタンタップで新しいエントリを挿入し、新しいセルにアニメーションだが一覧表示されます。私は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

を行挿入した後に、TextFieldファーストレスポンダを行います

新しい行が完全にアニメーション化が、titleTextFieldはなりませんbecomeFirstResponder

ここで私が試したものです。

+0

申し訳ありませんが、このコードを試してみてください、私は私が – Leon

+0

後にそれを直接呼び出す場合は、行のアニメーションを停止CTTransactionを外し、[のtableViewのinsertRowsAtIndexPathsような何かをしているようだと述べている必要があります:@ [indexPath] withRowAnimation: UITableViewRowAnimationLeft]; [cell.textLabel becomeFirstResponder]; – jagdish

+1

それも試してみました。 no luck – 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

編集編集の回答 –

関連する問題