Estoy tratando de hacer mi UITableView editable para que pueda mover las celdas. En este momento, cuando hago clic en el botón editar, solo me permite eliminar pero no reorganizar.¿Cómo hacer que UITableView se pueda reorganizar?
Los métodos que tengo son:
Code:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animate
{
[self.routineTableView setEditing: !self.routineTableView.editing animated:YES];
if (self.routineTableView.editing)
[self.navigationItem.leftBarButtonItem setTitle:@"Done"];
else
[self.navigationItem.leftBarButtonItem setTitle:@"Edit"];
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
[context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];
NSLog(@"fetched results : \n%@\n",[self.fetchedResultsController fetchedObjects]);
NSError *error = nil;
if (![managedObjectContext save:&error])
{
// Handle the error.
}
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}