Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView reordering cells in UIViewController - reorder control not showing

I'm trying to have UITableView with 2 classes of UITableViewCell (section 0 with one row, section 1 with [self.dataArray count] rows).

I tried these links: http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/ManageReorderRow/ManageReorderRow.html

reordering control in UITableView
Reorder control isn't displayed on table view

I've added:

    -(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{   

    // Get the object we are going to move
    Task *task = [[Task alloc] init];
    task = [self.taskArray  objectAtIndex:[destinationIndexPath row]];
    
    // We will delete and move it to another location so well have to retain it
    //[task retain];
    
    // Remove it an move it to other place
    [self.taskArray removeObjectAtIndex:[sourceIndexPath row]];
    [self.taskArray insertObject:task atIndex:[destinationIndexPath row]];
}


     // Override to support conditional rearranging of the table view.
     - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{
         if (indexPath.section == 1) {
             return YES;
         }
         return YES;
     }

And I did add for every UITableViewCell class:

cell.showsReorderControl = YES;

but still no luck, no reaorderControl is showing... anybody? This is quite urgent and annoying to have so many tutorials, but not working for me.

EDIT:

I changed a bit topic to include fact, that I was using UIViewController not UITableViewController.

like image 603
raistlin Avatar asked Nov 19 '12 22:11

raistlin


1 Answers

To implement row reordering in a UITableView, you need to implement tableView:canMoveRowAtIndexPath: and tableView:moveRowAtIndexPath:toIndexPath:, You might also want to implement tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:.

And the most important, the table view must be in edit mode for the reorder controls to appear.

like image 186
rmaddy Avatar answered Nov 01 '22 02:11

rmaddy