UITableView custom cell images disappear after scrolling.

前端 未结 2 1755
太阳男子
太阳男子 2021-01-03 05:11

I am in the process of creating my open grid view.

I created a custom cell that looks like so:

\"enter

相关标签:
2条回答
  • 2021-01-03 05:22

    I believe the problem is because your cells are being dequeued and you are populating cells in tableView:cellForRowAtIndexPath: using row information other than the indexPath.row.

    Maybe try something along the following lines:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSArray         * rssItems;
        id                rssItem;
        static NSString * MyIdentifier = @"Cell";
    
        TableGalleryCustomCell *cell = (TableGalleryCustomCell*)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    
        if( cell == nil) {
            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"TableGalleryCustomCell" owner:nil options:nil];
            for (id currentObject in topLevelObjects) {
                if ([currentObject isKindOfClass:[UITableViewCell class]]) {
                    cell = (TableGalleryCustomCell*)currentObject;
                    break;
                }
            }
        }
    
        rssItems =  [[self.appDelegate rssParser] rssItems];
        if (indexPath.row < [rssItems count]) {
            rssItem = [rssItems objectAtIndex:indexPath.row];
            cell.firstAddress.text = [rssItem Address];
            cell.firstPrice.text   = [rssItem Deposit];
            if ([[rssItem imageURLs] count] != 0 ) {
                [cell.firstImage setImageWithURL:[NSURL URLWithString:[[rssItem imageURLs] objectAtIndex:0.0]]];
                cell.firstImage.tag = indexPath.row;
            }
        }
    
        return cell;
    }
    
    0 讨论(0)
  • 2021-01-03 05:28

    Sharing my experience:

    Had similar problems. I have many tables in the app, and in one of them data would randomly disappear, and eventually the entire table would go away.

    The problem for me was that I was dequeueing cells, giving all of them the same "unique" id. So several tables were sharing the same id, and I believe they were conflicting and messing up the cells I was looking at.

    Giving each table it's own unique identifier solved the problem for me. (dah!)

    0 讨论(0)
提交回复
热议问题