我正在创建我的开放式 GridView 。
我创建了一个如下所示的自定义单元格:
我像这样处理它:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
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;
}
}
}
if (countingIndex < [[[self.appDelegate rssParser] rssItems] count]) {
cell.firstAddress.text = [[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] Address];
cell.firstPrice.text = [[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] Deposit];
if ([[[[[[self appDelegate] rssParser]rssItems]objectAtIndex:countingIndex] imageURLs] count] != 0 ) {
[cell.firstImage setImageWithURL:[NSURL URLWithString:[[[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] imageURLs] objectAtIndex:0.0]]];
cell.firstImage.tag = countingIndex;
}
}
countingIndex++;
if (countingIndex < [[[self.appDelegate rssParser] rssItems] count]) {
cell.secondAddress.text = [[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] Address];
cell.secondPrice.text = [[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] Deposit];
if ([[[[[[self appDelegate] rssParser]rssItems]objectAtIndex:countingIndex] imageURLs] count] != 0 ) {
[cell.secondImage setImageWithURL:[NSURL URLWithString:[[[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] imageURLs] objectAtIndex:0.0]]];
cell.secondImage.tag = countingIndex;
}
}
countingIndex++;
if (countingIndex < [[[self.appDelegate rssParser] rssItems] count]) {
cell.thirdAddress.text = [[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] Address];
cell.thirdPrice.text = [[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] Deposit];
if ([[[[[[self appDelegate] rssParser]rssItems]objectAtIndex:countingIndex] imageURLs] count] != 0 ) {
[cell.thirdImage setImageWithURL:[NSURL URLWithString:[[[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] imageURLs] objectAtIndex:0.0]]];
cell.thirdImage.tag = countingIndex;
}
}
countingIndex++;
if (countingIndex < [[[self.appDelegate rssParser] rssItems] count]) {
cell.fourthAddress.text = [[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] Address];
cell.fourthPrice.text = [[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] Deposit];
if ([[[[[[self appDelegate] rssParser]rssItems]objectAtIndex:countingIndex] imageURLs] count] != 0 ) {
[cell.fourthImage setImageWithURL:[NSURL URLWithString:[[[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] imageURLs] objectAtIndex:0.0]]];
cell.fourthImage.tag = countingIndex;
}
}
countingIndex++;
return cell;
}
它有点乱,但它有效.....直到我滚动。加载图像然后滚动出屏幕后图像消失。
我认为这可能是由于单元格的 imageViews 丢失了?
我尝试了完全相同的实现,但每个单元格中只有 1 个 imageView,并且一切正常。
任何指向正确方向的观点都将不胜感激。
感谢您的帮助,感谢您抽出时间。
最佳答案
分享我的经验:
遇到过类似的问题。我的应用程序中有很多表,其中一个表的数据会随机消失,最终整个表都会消失。
对我来说,问题是我正在使单元格出列,并为所有单元格提供相同的“唯一”ID。所以几个表共享相同的 ID,我相信它们相互冲突并弄乱了我正在查看的单元格。
为每个表赋予它自己的唯一标识符为我解决了这个问题。 (哒!)
关于objective-c - UITableView 自定义单元格图像在滚动后消失。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8981366/