У меня есть UITableViewController, который дублирует строки при прокрутке вниз. Я понимаю, что ячейки повторно используются, но я просто не могу понять, что делать, чтобы исправить это. Я читал другие подобные сообщения и не мог найти решение в моем случае.UITableViewController дублирует строки?
Что я делаю неправильно в своем коде, что приводит к дублированию ячеек?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"StringTableViewCell";
if (indexPath.row == 0) {
cellIdentifier = @"StringTableViewCell";
} else if (indexPath.row == 1) {
cellIdentifier = @"StringTableViewFooter";
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
// Sets up the table view cell accordingly based around whether it is the
// string row or the footer
if (cell) {
if ([cell isKindOfClass:[StringTableViewCell class]]) {
StringTableViewCell *stringCell = (StringTableViewCell *)cell;
// Sets the photos to the array of photo data for the collection view
[stringCell setCollectionData:self.images];
} else if ([cell isKindOfClass:[StringFooterTableViewCell class]]) {
// Sets the table view cell to be the custom footer view
StringFooterTableViewCell *footerCell = [[StringFooterTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"StringTableViewCellFooter"];
// Init's the footer with live data from here
[footerCell setStringUploaderName:@"Name"];
[footerCell setStringUploadDate:@"10 minutes ago"];
[footerCell setStringUploaderProfileImage:[UIImage imageNamed:@"avatar.jpg"]];
[footerCell setCommentButtonTitle:@"4.7k"];
[footerCell setLikeButtonTitle:@"11.3k"];
return footerCell;
}
}
return cell;
}
вы можете показать нам свой скриншот? – chancyWu
Ваш код поддерживает только две строки ячеек. Какие указательные пути должны быть для нижнего колонтитула, а какие указательные пути должны быть другого типа? – rmaddy
@rmaddy indexPath.row 0 для первой ячейки, а строка 1 для нижнего колонтитула. Я установил его в прошлом, когда я специально помещал нормальную ячейку ячеек или нижнего колонтитула условно под их соответствующими строками, но никаких изменений. – Jonathan