使用选定的单元格在UITableView中的部分之间滚动

时间:2016-04-14 12:20:17

标签: ios swift uitableview selection sections

我有一个带有两个部分的UITableView,我有一个按钮,可以将tableview更改为编辑模式,但只有底部可编辑。

当我选择行并仅在底部(在编辑模式下)滚动时,行保持选择。但是,如果我向上滚动直到隐藏底部部分并返回底部部分,则选择已被清除。

部分之间的滚动会清除选择。

为什么会这样?如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

所以只为了后代。一般来说,即使tableview单元格是同一类,如果它们在编辑性等方面有不同的行为,通常最好有两个单独的CellIdentifier字符串,以避免在状态之间进行大量切换。

可以像

一样简单
static NSString *CellIdentifier = @"Cell";
static NSString *CellIdentifier2 = @"Cell2";


NSString *identifierString = indexPath.section == 0 ? CellIdentifier:CellIdentifier2;

MYTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierString];

if (!cell)
    cell = [[MYTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifierString];