Ios 前3个单元格是相同的,但一旦我开始滚动,就可以正确显示了吗?
因此,每当我启动我的应用程序时,它看起来是这样的,前3个单元格都是一样的。但一旦我开始上下滚动,它就会修复,单元格2和单元格3会显示正确的信息 这就是我的代码目前的样子:Ios 前3个单元格是相同的,但一旦我开始滚动,就可以正确显示了吗?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,因此,每当我启动我的应用程序时,它看起来是这样的,前3个单元格都是一样的。但一旦我开始上下滚动,它就会修复,单元格2和单元格3会显示正确的信息 这就是我的代码目前的样子: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"MyFeedCell"; Sam
- (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
整个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;
}
可以肯定的是,NSLog(@“IMAGE:%@”,imageString);打印出三个不同的ImageString是否正确?它使用相同的图像打印了30多个字符串。为什么不能执行
RSSEntry*entry=[\u allEntries objectAtIndex:indexPath.row]代码>?另外,如果您登录\u allEntries
,所有图像是否与上面所述的相同?因为我正在尝试反转tableview单元格,而您的xib和tableCell子类设置错误。在如何重用单元格方面显然存在一些问题,请检查您的xib和tableCell设置,以确保文件所有者和所有内容都是正确的。我以前遇到过这个问题,结果证明我的xib设置是错误的。我会尝试使用我在topLevelObjects上发布的代码来修复它。啊,我发现了问题,切换registerClass和registerInB行(我在帖子中更新了它)。你必须在调用registerClass后调用RegisterInB。我的应用程序现在运行,这是一个好迹象。但它仍然在顶部显示相同的3个单元格和NSlog(@“Image:”);被调用的次数肯定超过30次。它正在被调用,但前三个输出是否不同?也许试着调用-reloaddatain-viewDidAppearI我通过RSS获取数据,你能看电视吗?