gpt4 book ai didi

iphone - 表编辑完成后,UISwitch 在 UITableViewCell 中仍然略微可见

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:22:42 24 4
gpt4 key购买 nike

我有一个奇怪的问题,UITableViewCelleditingAccessoryView 在表格编辑模式关闭后仍然显示。

目前,我正在使用 UISwitch 作为编辑辅助 View ,并让表格 View 在按下导航栏的编辑按钮时通过动画处理移动编辑 View 开/关屏幕。

几乎所有的编辑辅助 View 都可以在屏幕外正确地进行动画处理,但总有两个不能完全脱离屏幕,然后当单元格出列并重新使用时它们会被重新使用,因此它们会在滚动过程中出现。

有没有其他人看到过这个或者我在这里遗漏了什么?

我正在这样设置单元格:

- (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 方法以在延迟后重新加载表格数据以允许动画完成,但它仅有时有效

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];

// Insert/delete the stat rows depending on editing mode
[self rebuildTableDataAnimated:YES];

double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// Trying to fix bug that shows part of a UISwitch on screen still even though editing mode is completed
[self.tableView reloadData];
});
}

这是一个屏幕截图:

Bug image

最佳答案

旧线程,但在带有 UIStepper 的 Xcode 7 中遇到同样的问题。我的解决方案是将它嵌入到一个左右填充的 UIView 中,然后将父 View 设置为 editingAccessoryView。它有效,而且不像 hack。

关于iphone - 表编辑完成后,UISwitch 在 UITableViewCell 中仍然略微可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15175359/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com