0

I am working on an app where I need to reorder rows of section 1. I could achieve the reorder by implementing the tableView delegates. When the table is in editing mode I show reorder for section 1 and no controls for rest sections, but the rows of rest section should be deleted by swipe to left.

I am not sure whether this is possible but my requirement is exact the same.

Work done by me: Below are the delegates of tableView I implemented:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

    if ([self.myTable isEditing]) {
            return UITableViewCellAccessoryNone;
    }
    return UITableViewCellEditingStyleDelete;
}

-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1) {
        return YES;
    }
    return NO;
}

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

The above code made the edit mode look as I wanted. Re-order sign got visible for only section 1 & red delete button is also not visible for rest sections (as desired).

Problem: The rows of sections apart from section 1 were also not being deleted.When I swipe to left nothing happens.

In short in edit mode, section 1 should be re-order enabled and rest sections should work as they work in normal mode i.e swipe left to delete row should be functioning in tableview edit mode.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Dinakar
  • 1,198
  • 15
  • 37

1 Answers1

0

AFAIK you cannot achieve what you are trying. The two sections are part of the same table which is being edited. So once the table is in editing mode, it will affect all the sections and rows.

what you can do is divide the data in the two sections into two separate tables and load the tables in the header view of each section like this

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 0;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        TableViewController1 *tab1 = [[TableViewController1 alloc] initWithStyle:UITableViewStylePlain];
        return tab1.tableView;
    } else{
        TableViewController2 *tab2 = [[TableViewController2 alloc] initWithStyle:UITableViewStylePlain];
        return tab2.tableView;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return self.parentTable.frame.size.height/2;
}

tab1 will have data from first section and similar case for tab2 (forgive the variable naming). The parent table should have grouped style and also scrolling should be disabled for it. This way the two sections can be edited independent of each other. Also, this categorises data and each section becomes independently scrollable. Hope this helps and answers what ur looking for.

Prathamesh Saraf
  • 709
  • 4
  • 14