5

I have a tableView with 4 sections. I want to enable editing (move/drag/ rearrange ) the cells only within the forth section. When I set: tableView.editing = YES I get all the table view to be in editing mode. This How to limit UITableView row reordering to a section helped me as I can now rearrange cells from a section only within their "root" section.

What I mean is if the cell is in the 1st section then I only get to rearrange within the 1st section and not the others. My goal is to enable editing only with The 4th section therefore putting in Move/drag Mode only the cells within the 4th Section. Does anyone know how I can do this?

Community
  • 1
  • 1
user1780591
  • 207
  • 4
  • 14

1 Answers1

8

You can achieve this by implementing this delegate method

-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 3) {
        return YES;
    } else {
        return NO;
    }
}
tkanzakic
  • 5,499
  • 16
  • 34
  • 41
  • 5
    Shorter version: `return indexPath.section == 3`. :) – Vladimir Obrizan Apr 11 '13 at 20:52
  • @tkanzakic do you know how i can log the new arrangement of cells? – user1780591 Apr 11 '13 at 20:53
  • @tkanzakic The arrangement will construct a new array which will reflect to a button arrangement. e.g. cell: 1,2,3 will arrange buttons in another view according to 1,2,3 (buttons: a,b,c). If the arrangement is 2,3,1 then the buttons will be sort: b,c,a.. – user1780591 Apr 11 '13 at 21:08
  • you can assign a tag to each of the cell with the number you want and then use it – tkanzakic Apr 12 '13 at 06:02
  • 1
    It's better to use enums instead of magic numbers: `typedef NS_ENUM(NSInteger, MyControllerSection) { MyControllerSection1,... MyControllerSectionN, MyControllerSectionCount, };` and then `return indexPath.section == MyControllerSection3;` ;-) – voiger Apr 25 '16 at 12:40