Domanda

Il Three20 è grande biblioteca. Sta facendo il lavoro con tavoli molto facile. Ma una lacuna che ho notato - è l'eliminazione delle righe, con l'animazione. Ho trascorso molte ore cercando di fare questo, e questo è quello che sto facendo:

// 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];

Dopo questo codice viene eseguito appare l'errore: [NSCFArray objectAtIndex:]: indice (0) al di là di confini (0)

Sto utilizzando la classe ereditata dalla TTTableViewController. E io non implementa l'DataSourceDelegate o TableViewDelegate perché sto utilizzando il Three20 il più possibile. Quindi, questo è il modo creo origine dati:

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

Ho letto questo articolo ( articolo ) ma non aiuta: (

Quindi, so che questo è molto semplice per i guru da questo sito. Si può solo darmi campione avanzato di come fare questo

Grazie

È stato utile?

Soluzione

La prima cosa che ho posto è che si sta cancellando una riga dalla tabella quando la tabella non è in modalità di modifica.

Altri suggerimenti

Ho anche avuto "EXC_BAD_ACCESS" in model:didDeleteObject:atIndexPath: ma ho avuto quel problema risolto.

Per eliminare una riga in una TTTableViewController è necessario implementare tableView:commitEditingStyle: nell'implementazione DataSource in questo modo:

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

È inoltre necessario implementare tableView:willRemoveObject:atIndexPath: nel DataSource:

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

Il trucco è quello di cambiare il NSIndexPath ritorni contenere solo la sezione di esso si svuota. Poi il codice TTTableViewController rimuove la sezione al posto della cella.

HTH

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top