我正在创建我的开放网格视图。
我创建了一个自定义单元格,如下所示:
我像这样处理填充它:
- (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;
}
它有点乱,但它有效......直到我滚动。加载图像后,将其滚出屏幕,图像就会消失。
我相信这可能是由于细胞的图像视图丢失造成的?
我尝试了完全相同的实现,但每个单元格中只有 1 个 imageView,并且一切都很好。
任何正确方向的观点都将非常感激。
感谢您的帮助并感谢您的宝贵时间。
分享一下我的经验:
有类似的问题。我的应用程序中有很多表,其中一个表中的数据会随机消失,最终整个表都会消失。
对我来说,问题是我正在使单元出队,给它们所有相同的“唯一”id。因此,几个表共享相同的 id,我相信它们是冲突的,并且弄乱了我正在查看的单元格。
为每个表提供自己的唯一标识符解决了我的问题。 (哎呀!)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)