Ответ 1
Клетки снова используются. Вы должны reset accessView каждый раз. Его просто небольшое изменение:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TopicCell"];
GPBTopic *topic = [self.topics.list objectAtIndex:indexPath.row];
cell.textLabel.text= topic.name;
if ((indexPath.row == 5) || (indexPath.row == 9))
{
cell.accessoryView = [[ UIImageView alloc ] initWithImage:[UIImage imageNamed:@"lock_icon.png"]];
[cell.accessoryView setFrame:CGRectMake(0, 0, 24, 24)];
} else {
cell.accessoryView = nil;
}
return cell;
}
Просто для завершения, вы также можете использовать решение Eric следующим образом: оно может быть быстрее, поскольку imageView не создается каждый раз. Но это лишь минимальная разница. Вероятно, у ваших лагов есть другие причины.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
if(indexPath.row == 5 || indexPath.row == 9) {
cell = [tableView dequeueReusableCellWithIdentifier:@"TopicCellWithImage"];
cell.accessoryView = [[ UIImageView alloc ] initWithImage:[UIImage imageNamed:@"lock_icon.png"]];;
[cell.accessoryView setFrame:CGRectMake(0, 0, 24, 24)];
} else {
cell = [tableView dequeueReusableCellWithIdentifier:@"TopicCell"];
}
GPBTopic *topic = [self.topics.list objectAtIndex:indexPath.row];
cell.textLabel.text= topic.name;
return cell;
}