Я занимаюсь созданием открытого вида сетки.Пользовательские изображения ячейки UITableView исчезают после прокрутки.
Я создал пользовательский элемент, который выглядит так:
I ручка населяющий его следующим образом:
- (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 изображением в каждой ячейке, и все отлично работает.
Любая точка в правильном направлении была бы очень оценена.
Я ценю любую помощь и благодарю вас за ваше время.
благодарит за ваш ответ! Можете ли вы рассказать о «заполнении ячеек в таблицеView: cellForRowAtIndexPath: использование информации о строках, отличной от indexPath.row»?? Я думаю, что сталкиваюсь с той же проблемой и делаю то, что вы предлагаете. 10x! –
Когда вы прокручиваете вверх и вниз по таблицеView, indexPath.row будет соответственно увеличивать или уменьшать. Однако ваш код только увеличивается. Например, когда таблица загружается, строка запрашиваемых ячеек может быть 0, 1, 2 и 3. Если я прокручу вниз по двум ячейкам, тогда будут запрошены строки 4 и 5 (и, наоборот, ячейки 0 и 1 будут поставлены в очередь для последующего использования). Если я снова вернусь назад, а ячейки 1 и 0 будут запрошены, а ячейки 5 и 4 будут поставлены в очередь. В исходном коде с тем же сценарием будут загружены ячейки 0, 1, 2 и 3. Затем ячейки 4 и 5. Наконец 6 и 7. –
Предоставляли каждой ячейке свой собственный идентификатор с избыточным объемом памяти? – random