Cocoa Touch problema tabela de fonte de dados
-
22-08-2019 - |
Pergunta
Eu estou tendo alguns problemas com a exibição de resultados a partir de uma fonte de dados. Este código irá mostrar um resultado diferente (e correto) no console, mas os resultados em todos os tipos de lixo aleatório no simulador.
( "resultados" é uma propriedade NSMutableArray para a classe.)
-(void) handleSearchForKeywords: (NSString *) keywords {
[results removeAllObjects];
int r = rand() % 10;
for( int i = 0; i < r; i++ ) {
[results addObject:[NSString stringWithFormat:@"test %i: %@", i, keywords]];
}
[self reloadTheTable];
}
-(void) reloadTheTable {
NSLog( @"current array contents: %@", results );
[tableView reloadData];
}
Eu estou supondo que isso pode ter algo a ver com a retenção da memória da matriz, ou as cordas na matriz? Temo que ainda não tem o jeito disso.
[editar em resposta a Marc Bessey - Eu acho que tudo aqui é o seu métodos básicos de fonte de dados]
-(NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) section {
return [results count];
}
-(UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {
static NSString *SearchViewControllerCell = @"SearchViewControllerCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SearchViewControllerCell];
if( cell == nil ) {
cell = [[[UITableViewCell alloc] initWithFrame: CGRectZero reuseIdentifier: SearchViewControllerCell] autorelease];
NSUInteger row = [indexPath row];
[cell setText:[results objectAtIndex:row]];
}
return cell;
}
Solução
Eu não acho que o problema é no código que você postou. É mais provável no código que implementa a fonte de dados para a sua exibição de tabela.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow