我有一个UITableView
包含图像、文本和披露按钮的单元格。我正在加载这样的单元格:
- (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
,我点击的行没有显示任何披露按钮或活动指示器。我做错了什么?在无需重新加载表格视图的情况下切换这些控件的更好方法是什么?