tableview 上的 setediting = true 会使单元格附件视图消失吗?

use*_*645 3 objective-c uitableview ios

我在每个 tableview 单元格上都有一个 UISwitchView,并希望允许对单元格进行重新排序。问题是当我在 table view 上设置 setEditing=true 时,附件(switchview)消失了。有没有办法同时保留两者?

编辑

static NSString *CellIdentifier = @"Edit Sources Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

// Configure the cell...
NSUInteger row = [indexPath row];
Source *source = [self.sources objectAtIndex:row];

cell.textLabel.text = source.name;

UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
switchView.tag = row;
cell.accessoryView = switchView;
[switchView setOn:source.switchedOn animated:NO];
[switchView addTarget:self action:@selector(switchChangedForSource:)  forControlEvents: UIControlEventValueChanged] ;
Run Code Online (Sandbox Code Playgroud)

ben*_*ado 5

UITableViewCell 有一个附加属性,editingAccessoryView用于在单元格处于编辑模式时显示的视图。

我不知道您是否可以将相同的 UISwitch 实例分配给accessoryVieweditingAccessoryView属性,或者您是否需要创建两个实例。(一个视图一次只能有一个父级,但 UITableViewCell 实际上是在做显示视图的工作,所以它可能足够聪明来处理这种情况。)