nella mia app che uso UITableView con personalizzato cellule.Come prevenire UITableView dalle cellule riutilizzo personalizzati Swift
per ogni cella implementare la funzione per crearla e chiamare queste funzioni in cellForRow.
questo è un esempio di codice dal progetto:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.row == CellsTypes.profileImageCell.rawValue {
return createIntroCell()
}
else if indexPath.row == CellsTypes.fullNameCell.rawValue {
return createUserNameCell()
}
else if indexPath.row == CellsTypes.emailCell.rawValue {
return createEmailCell()
}
else {
return createPasswordCell()
}}
e queste sono le funzioni di creazione:
func createUserNameCell() -> TextFieldTableViewCell {
let fullNameCell = self.tableView.dequeueReusableCellWithIdentifier("text-field-cell") as! TextFieldTableViewCell
fullNameCell.awamirTextFieldNib.setNormalTextFieldCellContent("Full Name")
fullNameCell.awamirTextFieldNib.textFieldContent.tag = CellsTypes.fullNameCell.rawValue
fullNameCell.awamirTextFieldNib.textFieldContent.returnKeyType = .Next
fullNameCell.awamirTextFieldNib.textFieldContent.delegate = self
return fullNameCell
}
func createEmailCell() -> TextFieldTableViewCell {
let emailCell = self.tableView.dequeueReusableCellWithIdentifier("text-field-cell") as! TextFieldTableViewCell
emailCell.awamirTextFieldNib.setNormalTextFieldCellContent("Email")
emailCell.awamirTextFieldNib.textFieldContent.tag = CellsTypes.emailCell.rawValue
emailCell.awamirTextFieldNib.textFieldContent.returnKeyType = .Next
emailCell.awamirTextFieldNib.textFieldContent.delegate = self
return emailCell
}
func createPasswordCell() -> TextFieldTableViewCell {
let textFieldCell = self.tableView.dequeueReusableCellWithIdentifier("text-field-cell") as! TextFieldTableViewCell
textFieldCell.awamirTextFieldNib.setPasswordCellContent("Password")
textFieldCell.awamirTextFieldNib.textFieldContent.tag = CellsTypes.passwordCell.rawValue
textFieldCell.awamirTextFieldNib.textFieldContent.returnKeyType = .Next
textFieldCell.awamirTextFieldNib.textFieldContent.delegate = self
return textFieldCell
}
il problema è se ricarico tableView il contenuto delle celle cambiato a causa della reusablity delle cellule. vale a dire: dopo aver ricaricato la vista tabella il contenuto della prima cella diventa nella seconda cella e il contenuto della sencond diventa nella prima cella !!
Come impedire a tableview di riutilizzare le celle ?!
Grazie.
Non dovresti impedire questo, dovresti essere felice che 'UITableView' abbia questa abilità =) –
non devi impedire il riutilizzo delle celle ...invece dovresti imparare a riutilizzare le tue celle altrimenti farai un sacco di elaborazioni inutili e renderai la tua batteria inefficiente – Fonix
il tuo codice mi sembra un po 'disordinato, tu riutilizzi le celle, ma non è ovvio come stai _reset_ contenuto prima di impostarlo come _normal_, _pawwsord_, ecc ... – holex