Calling reloadRowsAtIndexPaths remove tableView contentOffset

Quando eu ligo

reloadRowsAtIndexPaths

My UITableView contentOffset foi removido. Existe um método delegado que eu possa usar para capturar a atualização da exibição da tabela e definir o Offset novamente, para que ele permaneça no lugar e não seja animado na exibição, ou simplesmente evite que isso seja feito?

Estou definindo o contentOffest em viewDidLoad:

self.tableView.contentOffset = CGPointMake(0, 43);

Aqui está um exemplo de uso:

[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[params valueForKey:@"index"], nil] withRowAnimation:UITableViewRowAnimationFade];

Que remove o contentOffset e o anima em exibição, o que eu não quer

Mais especificamente, isso parece ocorrer quando a linha que está sendo recarregada está em indexPath.section 0 e indexPath.row 0, ou seja, na linha superio

Mais Informaçõe

Estou chamando reloadRowsAtIndexPaths após uma solicitação assíncrona para buscar uma imagem de um servidor. Basicamente, funciona assim:

cellForRowAtIndexPath é chamado para verificar a presença do arquivo thumb no disco, se o arquivo não estiver presente, um espaço reservado será carregado no local e uma solicitação assíncrona será iniciada em um thread em segundo plano para buscar a imageQuando o download da imagem terminar, ligo parareloadRowsAtIndexPaths para a célula correta, para que a imagem correta desapareça no lugar da imagem do espaço reservadA quantidade de células pode ser diferente, pois a solicitação é chamada dentro de cellForRowAtIndexPath, para que as imagens sejam carregadas à medida que as células carregam

cellForRowAtIndexPath file check

paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_small.gif",[[listItems objectAtIndex:indexPath.row] valueForKey:@"slug"]]];

    if([[NSFileManager defaultManager] fileExistsAtPath:path]){

        listCell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:path]];

    } else {

        listCell.imageView.image = [UIImage imageNamed:@"small_placeholder.gif"];

        NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:[[[listItems objectAtIndex:indexPath.row] valueForKey:@"image"] valueForKey:@"small"],@"image",[NSString stringWithFormat:@"%@_small.gif",[[listItems objectAtIndex:indexPath.row] valueForKey:@"slug"]], @"name",indexPath,@"index",@"listFileComplete",@"notification",nil];

        [NSThread detachNewThreadSelector:@selector(loadImages:) toTarget:self withObject:params];

        [params release];

    }

Notificação de arquivo não carregada:

-(void)fileComplete:(NSNotification *)notification {

    [self performSelectorOnMainThread:@selector(reloadMainThread:) withObject:[notification userInfo] waitUntilDone:NO];
}

Recarregar células (codifiquei seções devido a um bug com números de seções estranhos sendo passados muito raramente, causando uma falh

-(void)reloadMainThread:(NSDictionary *)params {

    NSIndexPath *index;

    switch ([[params valueForKey:@"index"] section]) {
        case 0:
            index = [NSIndexPath indexPathForRow:[[params valueForKey:@"index"] row] inSection:0];
            [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[params valueForKey:@"index"], nil] withRowAnimation:UITableViewRowAnimationNone];
            break;
        default:
            index = [NSIndexPath indexPathForRow:[[params valueForKey:@"index"] row] inSection:2];
            [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:index,nil] withRowAnimation:UITableViewRowAnimationFade];
            break;
    }

}

questionAnswers(5)

yourAnswerToTheQuestion