Ho un problema un po 'strano, e non riesco a capire cosa mi manca. Ho un UITableView che è modificabile sul posto (vale a dire quando il mio UI è caricato, mando la mia tabella il setEditing: YES animato: messaggio YES). L'ultima riga della tabella è destinata alla riga "Aggiungi nuovo". Tutte le file tranne l'ultima riga nella mia tabella possono essere spostate. Nessuna delle righe può essere cancellata.Impossibile spostare le righe in un UITableView anche se sono visualizzate grabber
Le righe vengono visualizzate correttamente e i grabber vengono visualizzati sul lato destro di tutte le righe tranne l'ultima riga (come previsto). Il problema è che non riesco a spostare le righe. Quando tocco il grabber per spostare la riga, è un tipo di jiggles in atto, ma non riesco a trascinarlo verso l'alto o verso il basso. Ecco il relativo frammento di codice:
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleNone;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == [self.itemArray count]) {
return NO;
}
return YES;
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == [self.itemArray count]) {
return NO;
}
return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
Item *item = [self.itemArray objectAtIndex:fromIndexPath.row];
[self.itemArray removeObjectAtIndex:fromIndexPath.row];
[self.itemArray insertObject:item atIndex:toIndexPath.row];
}
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath {
if ([proposedDestinationIndexPath row] < [self.itemArray count]) {
return proposedDestinationIndexPath;
}
NSIndexPath *betterIndexPath = [NSIndexPath indexPathForRow:[self.itemArray count]-1 inSection:0];
return betterIndexPath;
}
Per cercare di eseguire il debug, sembra che il tableView: moveRowAtIndexPath: viene chiamato quasi immediatamente anche se ho in mano al grabber (vale a dire che non ho ancora alzato il dito). Inoltre, my tableView: targetIndexPathForMoveFromRowAtIndexPath: proposedDestinationIndexPath: non viene invocato affatto.
Qualche idea su cosa sto sbagliando? Qualche suggerimento su cosa dovrei provare a risolvere questo problema?
Possibile duplicato di [Impossibile trascinare UITableViewCell dalla posizione corrente durante il riordino] (http://stackoverflow.com/questions/9251735/cant-drag-uitableviewcell-from-its-current-position-when-reorder) – Daniel