Iphone SDK - Странное поведение с UITableView и UITableViewCellAccessory - PullRequest
0 голосов
/ 28 февраля 2011

У меня странное поведение при загрузке таблицы.

Таблица иногда загружается нормально, а иногда загрузка UITableViewCellAccessory добавляется в некоторые строки последнего раздела.

Вот код cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {</p> <pre><code>static NSString *CellIdentifier = @"Cell"; NSString *enabled= @"1"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; } if(indexPath.section == 0) { if(indexPath.row == 0) { cell.textLabel.text =[section1 objectAtIndex:0]; cell.accessoryType = UITableViewCellAccessoryNone; return cell; } } if(indexPath.section == 1) { if(indexPath.row == 0) { cell.textLabel.text =[section2 objectAtIndex:0]; cell.accessoryType = UITableViewCellAccessoryNone; return cell; } } if(indexPath.section == 2) { if(indexPath.row == 0) { cell.textLabel.text =[NSString stringWithFormat:@"Morning Time: %@" , [section3 objectAtIndex:0]]; cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; return cell; } if(indexPath.row == 1) { cell.textLabel.text =[NSString stringWithFormat:@"Afternoon Time: %@" , [section3 objectAtIndex:1]]; cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; return cell; } } if(indexPath.section == 3) { if(indexPath.row == 0) { cell.textLabel.text =@"Monday"; if([enabled isEqualToString:[section4 objectAtIndex:0]]){ cell.accessoryType = UITableViewCellAccessoryCheckmark; } return cell; } if(indexPath.row == 1) { cell.textLabel.text =@"Tuesday"; if([enabled isEqualToString:[section4 objectAtIndex:1]]){ cell.accessoryType = UITableViewCellAccessoryCheckmark; } return cell; } if(indexPath.row == 2) { cell.textLabel.text =@"Wednesday"; if([enabled isEqualToString:[section4 objectAtIndex:2]]){ cell.accessoryType = UITableViewCellAccessoryCheckmark; } return cell; } if(indexPath.row == 3) { cell.textLabel.text =@"Thursday"; if([enabled isEqualToString:[section4 objectAtIndex:3]]){ cell.accessoryType = UITableViewCellAccessoryCheckmark; } return cell; } if(indexPath.row == 4) { cell.textLabel.text =@"Friday"; if([enabled isEqualToString:[section4 objectAtIndex:4]]){ cell.accessoryType = UITableViewCellAccessoryCheckmark; } return cell; } if(indexPath.row == 5) { cell.textLabel.text =@"Saturday"; if([enabled isEqualToString:[section4 objectAtIndex:5]]){ cell.accessoryType = UITableViewCellAccessoryCheckmark; } return cell; } if(indexPath.row == 6) { cell.textLabel.text =@"Sunday"; if([enabled isEqualToString:[section4 objectAtIndex:6]]){ cell.accessoryType = UITableViewCellAccessoryCheckmark; } return cell; } } return cell;

}

Последняя строка имеет UITableViewCellAccessoryDetailDisclosureButton, но я никогда не настраивал эту кнопку в этом разделе и происходит случайно:

Спасибо

1 Ответ

1 голос
/ 28 февраля 2011

Вы получаете переработанный элемент, который ранее использовался для раздела 2 и, следовательно, имеет кнопку раскрытия.Поскольку вы изменяете только accessoryType, если день включен, вы никогда не удаляете кнопку раскрытия, если она не включена.

Самый простой способ исправить это:

cell.accessoryType = UITableViewCellAccessoryNone;

rightпосле удаления / создания ячейки.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...