我目前正在开发一款应用程序来学习iOS编程和Swift。我有一个包含两个主要子视图的视图,一个MKMapView和一个UITableView。当在MapView中选择某个注释时,我希望隐藏TableView中的某些单元格。如果取消选择注释,则应重新出现单元格。目前我这样做是通过将要隐藏的单元格的高度设置为0并调用 tableView.beginUpdates() tableView.endUpdates(),但这会导致我的自定义单元格中的各种AutoLayout约束中断。我还试图在将高度设置为0之前将单元格上的隐藏属性设置为true,但AutoLayout约束仍然被破坏。
I'm currently working on an app to learn iOS programming and Swift. I have a view which contains two main subviews, a MKMapView and a UITableView. When a certain annotation is selected in the MapView, I want certain cells in the TableView to be hidden. If the annotation is deselected the cells should reappear. Currently I do this by setting the height for the cells to be hidden to 0 and calling tableView.beginUpdates() tableView.endUpdates(), however this causes all kinds of AutoLayout constraints inside my custom cells to break. I've also tried to set the hidden property on the cell to true before setting the height to 0, but AutoLayout constraints are still being broken.
什么是正确的这样做的方法?
What would be the proper way to do this?
提前致谢。
推荐答案我的2美分:只是尝试将其中一个冲突约束的优先级降低到较低的值,如UILayoutPriorityDefaultHigh(如果在Interface Builder中使用750)或甚至更低,则取决于您的单元格的组成方式。 应该足以给自动布局系统一个关于哪个约束可以安全地打破的提示。可能你会想要打破定义距下边距的距离的约束。
My 2 cents: just try to lower the priority of one of the conflicting constraints to a lower value, like UILayoutPriorityDefaultHigh (750 if used in Interface Builder) or even lower, it depends on how you cell is composed. It should be enough to give the auto layout system a hint about which constraint can be safely broken. Probably you will want to break the constraint that defines the distance from the bottom margin.
更多推荐
如何在不违反AutoLayout约束的情况下隐藏UITableViewCells
发布评论