In my UITableView I have this said relationship
Department -< Employees
(array of names)
I have set up custom objects for each model.
Thanks to @Paulw11, the solution was that I did not account for the departmentFrom and departmentTo, as what I wanted was to Move Tom from Sales to Marketing
;
Thus the fix I have is:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
if (fromIndexPath != toIndexPath ) {
Department *departmentFrom = [_objects objectAtIndex:fromIndexPath.section];
Department *departmentTo = [_objects objectAtIndex:toIndexPath.section];
Employee *employee = [departmentFrom.employees objectAtIndex:fromIndexPath.row];
[departmentFrom.employees removeObjectAtIndex:fromIndexPath.row];
[departmentTo.employees insertObject:employee atIndex:toIndexPath.row];
[tableView reloadData];
}
}
Accepted Paulw11 answer.