2

I'm developing an application an I have a UITableView, I am using the following code to manage reordering:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellEditingStyleNone;
}
-(NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath{
if(proposedDestinationIndexPath.section==0 && proposedDestinationIndexPath!=sourceIndexPath){

    return proposedDestinationIndexPath;
}
else{
    return sourceIndexPath;
   }
}
-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{ 
   return YES;
}
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
  //move rows
}

it works fine, but I want to change the Reorder button position and implement something like Music queue list on iOS 8.4.

I want to change the reorder button to be on the scrollview which contents of the cell are and move with the cell. Screenshot: enter image description here

Thanks in advance :)

Niloufar
  • 512
  • 1
  • 5
  • 24
  • Look at these existing threads, maybe they can help? http://stackoverflow.com/questions/5109250/programmatically-move-animate-a-uitableview-row-from-one-position-to-another http://stackoverflow.com/questions/2313252/programmaticlaly-moving-rows-with-animation-in-uitableview – Gurtej Singh Aug 04 '15 at 06:32
  • @GurtejSingh Thanks, I'm using custom cell for my table view to manage swipe to delete and reorder together but the reorder button position conflicts with delete so I need to change the reorder button – Niloufar Aug 04 '15 at 06:45
  • can you please post some screenshots of what exactly is the problem you are facing? Thanks – Gurtej Singh Aug 04 '15 at 07:53
  • @GurtejSingh Thanks, I have added the screenshot and if you see, reorder button and delete button are collapsed! – Niloufar Aug 04 '15 at 08:09
  • Thanks for adding the screenshots. Can you please show the code of how you are adding the re-order button into the cell? I'll be able to comment once you show me the code for adding the button. Thanks! – Gurtej Singh Aug 04 '15 at 09:33
  • @GurtejSingh I've added the code for reordering with tableview existing delegates as shown in the question. please let me know what you want exactly. – Niloufar Aug 04 '15 at 09:58
  • I want to see how you are adding the re-order button to the cell, not the actual logic for the re-ordering code. As you mentioned you are using a custom cell, you must be adding the button to the cell, can you please show me that code – Gurtej Singh Aug 04 '15 at 10:02
  • @GurtejSingh That's exactly what I'm asking for. I am not adding the reorder button myself I'm using tableview delegates to manage reordering! – Niloufar Aug 04 '15 at 10:09
  • Oh ok. Does this thread help? http://stackoverflow.com/questions/19115167/ios7-uitableviewcell-reorder-control-overlap-detailtextlabel-with-uitableviewcel – Gurtej Singh Aug 04 '15 at 10:36

2 Answers2

1

According to this tutorial you can set UITableViewCellReorderControl as a part of UITableViewCellContentView so it will move with the cell's content:

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIView *reorderControl = [cell huntedSubviewWithClassName:@"UITableViewCellReorderControl"];
    UIView *contentView = [cell huntedSubviewWithClassName:@"UITableViewCellContentView"];

    UIView *resizedGripView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(reorderControl.frame), CGRectGetMaxY(reorderControl.frame))];
    [resizedGripView addSubview:reorderControl];
    [contentView addSubview:resizedGripView];

    //  Original transform
    CGAffineTransform transform = CGAffineTransformIdentity;

    //  Move reorderControl to the left with an arbitrary value
    transform = CGAffineTransformTranslate(transform, -100, 0);

    [resizedGripView setTransform:transform];
}
oozywaters
  • 1,171
  • 1
  • 8
  • 17
  • Thanks. It's great but still not same as what I want, I want the reorder button to move with the cell scrolling. you are just changing the button position, I want to change the reorder button view. – Niloufar Aug 04 '15 at 11:28
  • It will move with the cell scrolling because we set it as a subview of `UITableViewCell` content view. And you can fully customize reorder button. I will edit my answer to provide more info. – oozywaters Aug 04 '15 at 11:58
  • Just for your reference I'm using the following code to manage swipe for delete for my tableview cells and my cells are custom like this: https://github.com/adamraudonis/UITableViewCell-Swipe-for-Options – Niloufar Aug 04 '15 at 12:07
  • I'll try to recreate your case and provide you solution. Btw, how did you manage to enable swipe-to-delete while showing reorder control? – oozywaters Aug 04 '15 at 13:16
  • As I've shared with you I used this link - github.com/adamraudonis/UITableViewCell-Swipe-for-Options – to create swipe to delete and I used UITableView delegates for moving row as I shared in my question. – Niloufar Aug 08 '15 at 04:55
0

I solved my problem using the code here for reordering and then I used UITableView delegates as follow for swipe to delete.

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleDelete;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    //Remove selected cell from tableview and you data source
  }
}
Niloufar
  • 512
  • 1
  • 5
  • 24