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.

4

1 回答 1

0

AFAIK 你无法实现你正在尝试的东西。这两个部分是正在编辑的同一个表的一部分。因此,一旦表格处于编辑模式,它将影响所有部分和行。

您可以做的是将两个部分中的数据分成两个单独的表,然后像这样在每个部分的标题视图中加载表

-(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 将有来自第一部分的数据和 tab2 的类似情况(请原谅变量命名)。父表应该具有分组样式,并且应该禁用滚动。这样,两个部分可以相互独立地进行编辑。此外,这对数据进行分类,每个部分都可以独立滚动。希望这有助于并回答您正在寻找的内容。

于 2014-05-14T18:38:20.120 回答