0

所以每当我启动我的应用程序时,它看起来像这样,前 3 个单元格都是一样的。但是一旦我开始上下滚动它就会修复,单元格 2 和 3 显示正确的信息。

这是目前我的代码的样子:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"MyFeedCell";
    SampleTableCell *cell = (SampleTableCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"SampleTableCell" owner:self options:nil];
        for (id currentObject in topLevelObjects) {
            if ([currentObject isKindOfClass:[UITableViewCell class]]) {
                cell = (SampleTableCell *)currentObject;
                break;
            }
        }
    }
    // Configure the cell.
    NSUInteger row = [indexPath row];
    NSUInteger count = [_allEntries count];
    RSSEntry *entry = [_allEntries objectAtIndex:(count-row-1)];
    NSString *imageString = entry.image;
    imageString = [imageString stringByReplacingOccurrencesOfString:@"128x67" withString:@"768x432"];
    NSLog(@"IMAGE : %@", imageString);

    NSURL *imgURL = [[NSURL alloc] initWithString:imageString];
    [cell.profilePicture setImageWithURL:imgURL placeholderImage:[UIImage imageNamed:nil]];
    NSString *date = [entry.articleDate substringToIndex:12];
    cell.datePosted.text = date;
    cell.name.text = entry.articleTitle;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;


    return cell;
}

这是它当前如何运作的 gif 图像 http://gyazo.com/2011099496257445c008a717beabd8fd

4

1 回答 1

0

不再需要整个 topLevelObjects 策略,用这个替换你的代码,看看你是否仍然遇到问题:

//this above @interface
static NSString *CellIdentifier = @"MyFeedCell";

//Put this in viewDidLoad
[self.table registerClass:[SampleTableCell class] forCellReuseIdentifier:CellIdentifier];
[self.table registerNib:[UINib nibWithNibName:@"SampleTableCell" bundle:nil] forCellReuseIdentifier:CellIdentifier]


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    SampleTableCell *cell = (SampleTableCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

       // Configure the cell.
    NSUInteger row = [indexPath row];
    NSUInteger count = [_allEntries count];
    RSSEntry *entry = [_allEntries objectAtIndex:(count-row-1)];

    NSString *imageString = entry.image;
    imageString = [imageString stringByReplacingOccurrencesOfString:@"128x67" withString:@"768x432"];
    NSLog(@"IMAGE : %@", imageString);

    NSURL *imgURL = [[NSURL alloc] initWithString:imageString];
    [cell.profilePicture setImageWithURL:imgURL placeholderImage:[UIImage imageNamed:nil]];

    NSString *date = [entry.articleDate substringToIndex:12];
    cell.datePosted.text = date;
    cell.name.text = entry.articleTitle;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;


    return cell;
}
于 2013-11-08T00:10:26.330 回答