Pregunta

Estoy teniendo algunos problemas con la visualización de los resultados de una fuente de datos. Este código mostrará un resultado diferente (y correcta) en la consola, pero da lugar a todo tipo de basura al azar en el simulador.

( "Resultados" es una propiedad NSMutableArray para la clase.)

-(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];
}

supongo que esto podría tener algo que ver con la retención de la memoria de la matriz, o las cadenas de la matriz? Me temo que todavía no han captado el punto de ello.

[editar en respuesta a Marc Bessey - Creo que todo aquí es sus métodos básicos del origen de datos]

-(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;
}
¿Fue útil?

Solución

No creo que el problema está en el código que has publicado. Es más probable en el código que implementa el origen de datos para su vista de tabla.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top