【发布时间】:2021-01-29 10:28:25
【问题描述】:
我正在构建一个包含聊天功能的应用。发送/接收消息时,聊天会显示在其他聊天的顶部(如在所有聊天应用程序中,例如 Instagram、WhatsApp 等)。
以特定顺序显示与人 a、b 和 c 的 3 个聊天的图像。如果现在,人 c 向您发送消息,该特定聊天单元格将显示在其他单元格的顶部,因为它是您发送/接收的最新消息。
我已经使用来自 firebase 的单个实时侦听器来实现这一点。
如果我现在收到来自人员 c 的此消息,而我不在显示所有消息概述的屏幕上,则 tableview 被告知在不可见时重新排序,显示此错误:
Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes.
一切正常,但我仍然不确定这是否是重新加载 tableview 和一般控制器的正确方法,如果它们不可见的话。如果它们再次可见/布局,更流畅的解决方案只会更新 tableview 的内容(通常是控制器)。
【问题讨论】:
-
看起来您在问题中回答了自己。在将表视图添加到超级视图之前不要更新它。当你要展示它时做它
标签: swift firebase uitableview