gpt4 book ai didi

iphone - (iPad/iPhone) 在屏幕上刷新表格单元格

转载 作者:行者123 更新时间:2023-12-03 21:05:52 24 4
gpt4 key购买 nike

我有一个带有自定义单元格的表格 View ,每个单元格都有图像和一些必须从网页解析的文本。我有一个操作队列,它从页面获取数据,并在加载每个页面的数据后调用 tableviewcontroller 中的方法 (void)addLoadedImageAndExcerpt:(NSString *)imgExc 并将数据存储在 2 个数组中。一旦与它关联的图像和文本加载到这两个数组(名为“articleExcerpts”和“imageDataObjects”)中,我需要刷新每个单元格。

方法如下:

- (void)addLoadedImageAndExcerpt:(NSString *)imgExc {
NSArray *imgAndExcerpt = [imgExc componentsSeparatedByString:@"{|}"];
[articleExcerpts addObject:[imgAndExcerpt objectAtIndex:1]];

NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: [imgAndExcerpt objectAtIndex:0]]];
[imageDataObjects addObject:imageData];
//count how many rows have been loaded so far.
loadedCount ++;

[self.table reloadData];//table is a UITableView

[imageData release];
}

问题是,当单元格在屏幕上时我无法更改它们。一旦我滚动,它们就会显示正确的数据,而它们在屏幕上时,我无法让它们更改。我尝试了概述的方法 herehere ,但它们不起作用。我尝试为相关行调用 tableView:cellForRowAtIndexPath: 并修改变量,但这并没有解决任何问题,因为该方法似乎每次被调用时都会创建一个新单元格,并且不会得到现有的(我将进一步发布该方法的代码)。
现在使用 [self.table reloadData] 似乎也没有做任何事情,这真的让我感到困惑......

我的tableView:cellForRowAtIndexPath:方法(我打赌问题就在这里。我不相信我正确地创建了自定义单元格)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomizedCell";

CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {

NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];

for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (CustomCell *) currentObject;
break;
}
}
}

// Configure the cell...

//title
cell.titleString = [titles objectAtIndex:indexPath.row];
//date
cell.dateString = [dates objectAtIndex:indexPath.row];

//Photo. check if imageDataObjects array is complete up to the current row yet
if (loadedCount > indexPath.row) {
if ([imageDataObjects objectAtIndex:indexPath.row] != @"NA") {
cell.imageData = [imageDataObjects objectAtIndex:indexPath.row];
} else {
cell.imageData = NULL;
}
}

//Excerpt. check if loadedCount array is complete up to the current row yet
if (loadedCount > indexPath.row) {
cell.exerptString = [articleExcerpts objectAtIndex:indexPath.row];
}

return cell;
}

我错过了什么?

最佳答案

我以前也遇到过类似的问题,并且能够通过包含这些行来使其工作

[table beginUpdates];
[table endUpdates];

在接收数据的方法末尾(因此,一旦您拥有填充单元格的数据,请调用它们)。

希望这也适合您!

关于iphone - (iPad/iPhone) 在屏幕上刷新表格单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7153462/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com