设备旋转中断后iOS 11中的UITableViewCell操作

设备旋转中断后iOS 11中的UITableViewCell操作,ios,uitableview,Ios,Uitableview,我使用标准的UITableView和UITableViewRowAction类。在iOS 11中,在设备旋转后,我有奇怪的行为,下面是示例: 基本上,它打破了表视图。在具有更复杂单元格和表格的实际应用程序中,情况更糟(单元格重叠等),我已经尝试在旋转后在UITableView上调用SetNeedsDisplay(),但没有帮助 在iOS 10中,操作看起来稍有不同,并且工作得非常完美。一些评论提到了这一点,但明显的赢家是取消对单元格的轮换编辑: - (void)viewWillTransiti

我使用标准的UITableView和UITableViewRowAction类。在iOS 11中,在设备旋转后,我有奇怪的行为,下面是示例:

基本上,它打破了表视图。在具有更复杂单元格和表格的实际应用程序中,情况更糟(单元格重叠等),我已经尝试在旋转后在UITableView上调用SetNeedsDisplay(),但没有帮助


在iOS 10中,操作看起来稍有不同,并且工作得非常完美。

一些评论提到了这一点,但明显的赢家是取消对单元格的轮换编辑:

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
    [self.tableView setEditing:NO animated:NO];
}
-(void)视图将转换大小:(CGSize)带有转换协调器的大小:(id)协调器
{
[super ViewWillTransitionSize:size with TransitionCoordinator:coordinator];
[self.tableView setEditing:无动画:无];
}
Swift版本:

您可以重置单元格的编辑状态,以便使用
setEditing(quo:animated:)
inside
viewWillTransition(to:with:)
不再显示操作,该操作在设备旋转时调用

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)

    tableView.setEditing(false, animated: true)
}

这仅在调用协调器的
动画
方法时有效。在
动画
块内将编辑设置为false将无效。

我在as
UIContextualAction中有一个自定义图像
,仅在设置
表视图时,我仍然面临一些问题。在
超级之后设置编辑(false,animated:true)
,我不得不将它嵌入到没有动画的perform中,现在它可以正常工作:)


在我的例子中,被接受的答案存在一个问题,即旋转后,表格不再可编辑。我在将其设置为false后直接将editing设置为true进行了修复:

tableView.setEditing(false, animated: false)
tableView.setEditing(true, animated: false)

我承认这是一种黑客式的、更好的解决方案(欢迎;)

尝试在旋转方法中重新加载tableView。@sharadchauhan它实际上可以工作,只是看起来很糟糕:)可能还有其他解决方案或至少是想法吗?尝试取消选择ViewWillTransitionOnToSize上的行:withTransitionCoordinator@AntonioM显示的操作不是行选择。找到了解决方案:我在willRotate()中调用UITableView.setEditing(false,false)。
tableView.setEditing(false, animated: false)
tableView.setEditing(true, animated: false)