The following method loads data from an array into custom cells of UITableView. The data is loaded in correctly. However, when I scroll down data in the above cells (the cells not visible) are changed to seemingly random elements in the array.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { cellComments=nil; cellComments=(FullCommentCell *)[tableView dequeueReusableCellWithIdentifier:FullCommentCell_ID]; if(cellComments==nil) { [[NSBundle mainBundle]loadNibNamed:@'FullCommentCell' owner:self options:nil]; } NSString *row = [NSString stringWithFormat:@'#%i',indexPath.row+1]; [cellComments loadFullComments:[latestFMLComments objectAtIndex:(indexPath.row+1)] withCommentNumber:row]; //cellComments.userInteractionEnabled=NO; return cellComments; }
I also have the following method that handles when i click on a cell. When the data of a cell changes to some random element in the array – if i click on the cell (which calls the method below) the data in the cell is changed to the right data.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self tableView:tableView cellForRowAtIndexPath:indexPath]; }
Any ideas why this is happening??
I changed the UITextView to a multi-line UILabel and the everything works now. I am not sure why this makes a difference – but hey it works 🙂