2016-07-20 27 views
6

Zgodnie z tytułem, mam UITextField wewnątrz UITableViewCell.UITextField w UITableViewCell staje sięFirstResponder po wstawieniu

Moje tableView wymienia elementy w tablicy o nazwie tallies: [String]

jestem dodanie nowego wpisu na przycisku TAP i animowanie w nowej komórce. Chcę, aby titleTextField do becomeFirstResponder po zakończeniu rowAnimation, ale jak dotąd nie może go uruchomić.

Nowy rząd animuje się doskonale, ale titleTextField nie becomeFirstResponder

będą Oto co próbowałem:

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() 

Odpowiedz

0

Producent textField pierwszy responder po wierszu wprowadzania.

+0

Niestety, ja muszę stwierdzić, że wydaje się, aby zatrzymać animację wiersza jeśli zgłoszę go bezpośrednio po – Leon

+0

Usuń CTTransaction i zrobić coś takiego [insertRowsAtIndexPaths Tableview: @ [indexPath] withRowAnimation: UITableViewRowAnimationLeft]; [cell.textLabel getFirstResponder]; – jagdish

+1

Wypróbowałem też. bez powodzenia – Leon

0

wypróbować ten kod

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

To nie zadziała, ponieważ 'komórka' jest zdefiniowana w bloku – Leon

+0

, ale musisz to zrobić po CATransaction.commit() –

+0

sprawdź edytowaną odpowiedź –