Pregunta

El Three20 es gran biblioteca. Se trata de hacer el trabajo con tablas muy fácil. Sin embargo, una brecha que me di cuenta - es la eliminación de filas, con la animación. He pasado muchas horas tratando de hacer esto, y esto es lo que estoy haciendo:

// get current index patch
UITableView* table = [super tableView];
NSIndexPath *indexPath = [table indexPathForSelectedRow];

//delete row in data source
TTListDataSource * source = (TTListDataSource *)self.dataSource;
[source.items removeObjectAtIndex:indexPath.row]; 

// delete row from the table, with animation
[table deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

Después de este código se ejecuta aparece el error: [NSCFArray objectAtIndex:]: índice (0) más allá de límites (0)

Estoy utilizando la clase heredada de la TTTableViewController. Y yo no implementa la DataSourceDelegate o TableViewDelegate porque estoy usando el Three20 tanto como sea posible. Por lo tanto, se trata de cómo creo fuente de datos:

for(NSDictionary *album in (NSArray *)albums){

TTTableRightImageItem *item = [TTTableRightImageItem itemWithText:@"name"  
            imageURL:@"image url" 
           defaultImage:nil 
          imageStyle:TTSTYLE(rounded)
           URL:@"url of selector where I actually catch the tap on a row"];
[tableItems addObject:item];
}
self.dataSource = [TTListDataSource dataSourceWithItems:tableItems];

He leído este artículo ( artículo ) pero no ayuda: (

Por lo tanto, sé que esto es muy simple para los gurús de este sitio. Puede que sólo me dan muestra de avanzada de cómo hacer esto

Gracias

¿Fue útil?

Solución

Lo primero que diviso es que va a eliminar una fila de la tabla cuando la tabla no está en modo de edición.

Otros consejos

También tengo "EXC_BAD_ACCESS" en model:didDeleteObject:atIndexPath: pero tengo ese problema resuelto.

Para eliminar una fila en un TTTableViewController es necesario implementar tableView:commitEditingStyle: en su implementación de DataSource como esto:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
        forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        id object = [[self.items objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];

        [self.model didDeleteObject:object atIndexPath:indexPath];
    }
}

También es necesario poner en práctica tableView:willRemoveObject:atIndexPath: en su origen de datos:

- (NSIndexPath*) tableView:(UITableView *)tableView willRemoveObject:(id)object atIndexPath:(NSIndexPath *)indexPath {
    // delete the object
    [object deleteFromDB];

    // removeItemAtIndexPath returns YES if the section is removed
    if ([self removeItemAtIndexPath:indexPath andSectionIfEmpty:YES]) {
        // remove an index path only to that section
        return [NSIndexPath indexPathWithIndex:indexPath.section];
    } else {
        return indexPath;
    }
}

El truco es cambiar el NSIndexPath regrese a sólo contienen la sección de él se vacía. A continuación, el código en la sección TTTableViewController elimina en lugar de la célula.

HTH

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