如何在不违反AutoLayout约束的情况下隐藏UITableViewCells

编程入门 行业动态 更新时间:2024-10-27 17:22:33
本文介绍了如何在不违反AutoLayout约束的情况下隐藏UITableViewCells的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前正在开发一款应用程序来学习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

本文发布于:2023-10-09 02:12:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1474412.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:情况下   如何在   AutoLayout   UITableViewCells

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!