我想讓我的UITableView可編輯,所以你可以移動單元格。現在,當我點擊編輯按鈕時,它只會讓我刪除,但不會重新排列。如何讓UITableView重新排列?
我的方法是:
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;
}