У меня есть UITableView
, в котором есть ячейки с изображениями, текстом и кнопкой раскрытия. Я загружаю клетки, как это:UITableViewCellAccessoryDetailDisclosureButton исчезает после замены UITableViewCell аксессуар
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
if ([indexPath row] == [[self multas] count]) {
[[cell textLabel] setText:@"Carregar mais..."];
}
else
{
Multa *multa = [self.multas objectAtIndex:indexPath.row];
NSString *dataIsolada = [[NSString stringWithFormat:[multa dataOcorrencia]] substringWithRange:NSMakeRange(0, 10)];
[[cell textLabel] setText:[NSString stringWithFormat:dataIsolada]];
[[cell detailTextLabel] setText:[multa descricao]];
[cell.imageView setImageWithURL:[NSURL URLWithString:[multa fotoURL]]
placeholderImage:[UIImage imageNamed:@"carregando.jpeg"]];
[cell.imageView setContentMode: UIViewContentModeScaleAspectFit];
[cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
}
return cell;
}
Когда пользователь нажимает на кнопку раскрытия, я включаю кнопку раскрытия для индикатора активности и затем нажмите другой вид экрана с помощью навигационного контроллера:
- (void)carregarDetalhesMulta:(UITableView *)tableView comMulta:(Multa *)multa
{
DetalheMultaViewController *form = [[DetalheMultaViewController alloc] initWithMulta:multa];
form.delegate = self;
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:form];
[self presentModalViewController:navigation animated:YES];
}
- (void) tableView: (UITableView *) tableView accessoryButtonTappedForRowWithIndexPath: (NSIndexPath *) indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleGray];
spinner.frame = CGRectMake(0, 0, 24, 24);
cell.accessoryView = spinner;
[spinner startAnimating];
Multa *multa = [self.multas objectAtIndex:indexPath.row];
double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[spinner stopAnimating];
[self carregarDetalhesMulta:tableView comMulta:multa];
[cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
});
}
Обратите внимание, что в конце я изменил аксессуар для кнопки раскрытия. Проблема заключается в следующем: когда я вернусь (нажав кнопку назад) на представление, содержащее UITableView
, строка, которую я нажал, не показывает кнопку раскрытия информации и индикатор активности. Что я делаю неправильно? Какой лучший способ переключить эти элементы управления, не перезагружая представление таблицы?
make cell.accessoryView = NULL; а затем используйте свой код. –