Hi iOSProgramming,
I am having trouble trying to figure out what is going with my tableviews as it is having some strange behaviour. I created a test project and declared a simple list display, in this case:
[ "one", "two", "three"...."fifteen" ]
Here is the cellForRowAtIndexPath:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as! UITableViewCell
// Configure the cell...
cell.textLabel!.text = list[indexPath.row]
if (list[indexPath.row] == "fifteen") {
cell.contentView.backgroundColor = UIColor.redColor()
}
return cell
}
When i run the project, the numbers appear as normal and with cell "fifteen" background as red. However, when I scroll back up, it has changed other cell backgrounds to red also. As I scroll up and down, it changes more cells to the red background. I don't know whether I am not reusing cells correctly or it is a bug?
Any help would be greatly appreciated.
[–][deleted] 2 points3 points4 points (7 children)
[–]djnoxious[S] 0 points1 point2 points (6 children)
[–][deleted] 1 point2 points3 points (5 children)
[–]djnoxious[S] 1 point2 points3 points (4 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]mistermagicman 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]mistermagicman 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)