关于表格编辑模式关闭后,editingAccessoryView
的{{1}}仍然存在一个奇怪的问题。
目前我正在使用UITableViewCell
作为编辑附件视图,并且当按下导航栏的编辑按钮时,让表视图处理按动画移动编辑视图的开/关屏幕。
几乎所有编辑配件视图都在屏幕上正确显示动画,但总有两个视图不能完全脱离屏幕,然后当单元格出列并重新使用时它们会被重复使用,以便在滚动时显示它们。
有没有其他人看过这个或者我在这里缺少什么?
我正在设置这样的单元格:
UISwitch
我已经尝试重写- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
AllStatCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AllStatCell"];
if (cell.editingAccessoryView == nil) {
UISwitch *statSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
[statSwitch addTarget:self action:@selector(saveSwitchState:) forControlEvents:UIControlEventValueChanged];
cell.editingAccessoryView = statSwitch;
}
NSString *statName = [self statNameForIndexPath:indexPath];
cell.statName.text = statName;
[(UISwitch *)cell.editingAccessoryView setOn:[self switchValueForIndexPath:indexPath withStatNamed:statName]];
if (tableView.editing) cell.statValue.hidden = YES;
return cell;
}
方法,在延迟后重新加载表数据以允许动画完成,但它只能运行
setEditing
这是一个屏幕截图:
答案 0 :(得分:1)
旧线程,但在Xcode 7中使用UIStepper时遇到同样的问题。我的解决方案是将它嵌入到左侧和右侧有一些填充的UIView中,然后将父视图设置为editingAccessoryView。它起作用,而不是一个黑客。
答案 1 :(得分:0)
感觉就像这样的黑客,所以希望其他人有更好的解决方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
AllStatCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AllStatCell"];
NSString *statName = [self statNameForIndexPath:indexPath];
// Hack fix for a bug that shows part of a UISwitch on screen still even though editing mode is completed
// Configure stat on/off switches
cell.editingAccessoryView = [self cellEditingAccessoryViewForEditing:tableView.editing];
if (tableView.editing) [(UISwitch *)cell.editingAccessoryView setOn:[self switchValueForIndexPath:indexPath withStatNamed:statName]];
cell.statName.text = statName;
[cell.statValue setHidden:tableView.editing];
return cell;
}
// Hack fix for a bug that shows part of a UISwitch on screen still even though editing mode is completed
- (UISwitch *)cellEditingAccessoryViewForEditing:(BOOL)tableIsEditing
{
if (tableIsEditing) {
UISwitch *statSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
[statSwitch addTarget:self action:@selector(saveSwitchState:) forControlEvents:UIControlEventValueChanged];
return statSwitch;
}
return nil;
}