parse.com PFQueryTableViewController está voltando para o mesmo objeto várias vezes

StackOverflow https://stackoverflow.com//questions/21000605

  •  20-12-2019
  •  | 
  •  

Pergunta

Estou tentando usar (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object para personalizar a exibição de PFObject de dados em um PFQueryTableViewController.Então eu construir a minha PFQuery objeto (PFQuery *)queryForTable no meu PFQueryTableViewController delegate que é suposto para obter a vários objetos em um NSArray.

Eu pensei que parse.com é suposto para, em seguida, enviar/chamada (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object uma vez para cada um dos objetos retornados.No entanto, eu acho que ele mantém a devolver o mesmo objeto várias vezes.

Assim, por exemplo, em vez de 3 objetos diferentes para o 3 vezes (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object é chamado, eu tenho o mesmo objeto.Mas não é um problema com os dados ou a consulta, porque no final do (PFQuery *)queryForTable , pouco antes de

return query;

Eu tentei

[query findObjectsInBackgroundWithBlock:^(NSArray *resultsNow,NSError *error) {NSLog(@"We have the following: %@", resultsNow);}];
 sleep(5);

e isso mostra o 3 objetos obtidos corretamente.Como é que a exata mesmo consulta quando tratado pelo PFQueryTableViewController chamar (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object 3 vezes, em vez de enviar os 3 objetos, um por um, ele envia o primeiro 3 vezes?

Em resposta a Wain perguntas, eu adicionei algumas respostas nos comentários, mas também parece relevante:

- (PFObject *)objectAtIndex:(NSIndexPath *)indexPath {
// overridden, since we want to implement sections
if (indexPath.section < self.objects.count) {
    return [self.objects objectAtIndex:indexPath.section];
}

return nil;
}
Foi útil?

Solução 2

Graças a Wain pergunta, eu registrada objectsDidLoad:e descobri que o correto 3 objetos estavam carregando, por isso tinha de ser uma questão de PFQueryTableViewController apenas não carregá-los na seqüência correta em (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object.

Em particular, o mapeamento era suposto ser em -(PFObject *)objectAtIndex:(NSIndexPath *)indexPath como indicado na minha pergunta.Mas após examinar a documentação para o n-Ésimo tempo, de repente eu notei que o nome do método, na verdade, deve ser -(PFObject *)objectAtIndexPath:(NSIndexPath *)indexPath.Não admira que ele não estava sendo chamado, e o meu mapeamento foi entrar em vigor, e, portanto, o objeto errado estava sendo passado para (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object.Quando eu mudei para -(PFObject *)objectAtIndexPath:(NSIndexPath *)indexPath, o problema foi embora!

Como poderia eu tenho errado o nome do método?Eu achei que eu tinha copiado o mapeamento exemplo do anypic código, então eu estou supondo que parse.com alterado o nome do método em algum momento após o anypic foi escrito?Alguém pode verificar?Eu estou usando analisar o quadro 1.2.14

Outras dicas

Eu tive um problema semelhante e o que eu fiz foi:

1 - em Vez de usar PFQueryTableViewController é só usar regularmente UITableViewController.

2 - para Alterar o método de queryForTable:para (void).

- (void)queryForTable {

3 - Eliminar PFQueryTableViewmétodos e implementar DataSourcemétodos.

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    {
    }
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
    }
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    }

Chamada [self queryForTable] no viewDidLoad depois de declarar-lo .h ficheiro.

Se você não usar o bloco, que você acabou de criar NSArray property e preencher no queryForTable:

self.yourarray = [query findobjects];

Se você usar o bloco, apenas certifique-se de preencher NSArraydentro do bloco e recarregar tableview.

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

    if (error) {
        // There was an error, do something with it.
    }
    else {
        self.yourArray = objects;
    }
    // Reload your tableView Data
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.tableView reloadData];
    }); 
}];

Isto é como eu tenho que trabalhar.Espero que ajude.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top