In my application, I use UITableView with custom cells.
for each cell, I implement a function to create it and call these functions in cellForRow.
This is an example of code from a project:
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() }}
and these are the creation functions:
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 }
the problem is that if I reload the table, the contents of the cells have changed due to the reuse of the cells. ie: after restarting the tableview, the contents of the first cell will become in the second cell, and the contents of sencond on will become in the first cell !!
How can I prevent the display of a table view in cells ?!
Thanks.
source share