swift - 如何通过访问它们的 isHidden 属性来显示多个 UIView?
问题描述
我想根据下面的逻辑语句在集合单元格中显示多个 UIView。
此功能适用于我的标签栏应用程序中的日历视图。我正在从 Firebase Firestore 上的数据库中读取事件并将其保存在calData
.
func configureEventDotFor(cell: CalendarCell, cellState: CellState) {
let dateString = self.globalFormatter.string(from: cellState.date)
for event in self.calData.events! {
let eventDateString = self.globalFormatter.string(from: event.startDate)
if dateString != eventDateString {
cell.holidayBar.isHidden = true
cell.birthdayBar.isHidden = true
cell.defaultBar.isHidden = true
} else if event.category == "birthday" {
cell.birthdayBar.isHidden = false
} else if event.category == "holiday" {
cell.holidayBar.isHidden = false
} else if event.category == "default" {
cell.defaultBar.isHidden = false
} else {
return
}
}
}
中有四个事件calData
,2 个默认,1 个假期和 1 个生日。生日和节日活动在同一天,因此两者都birthdayBar
应该holidayBar
在当天可见。我还希望看到defaultBar
其他两个事件的 a,但是当我运行应用程序时,只有 holidayBar 可见。
解决方案
问题是您似乎试图直接弄乱 UICollectionView 的单元格的子视图。不要那样做。只需cellForItemAt
根据一些易于访问的状态(通常是数据模型的内容)在方法中设置每个子视图的显示/隐藏状态。如果状态发生变化,只需重新加载集合视图。
推荐阅读
- javascript - Nodejs .Unable to send oauth v1 params in get request with axios
- php - 您的要求无法解决为一组可安装的软件包。- Laravel 流明邮件
- linux - linux - df 命令说磁盘 100% 已使用,但实际上并非如此
- asp.net-mvc-4 - 需要一种在网页中嵌入 rdlc 设计器的方法
- java - 单击毕加索时如何显示图像
- crystal-reports - 如何将一些十进制数字删除到业务伙伴帐龄(摘要报告)字段?
- php - 如何使用确切数量的参数查找函数调用
- c++ - 什么会在这个程序中产生内存泄漏
- xamarin.forms - 将 AutoMapper 从 7.0.0 升级到 9.0.0 后面临映射异常
- api - Microsoft Graph 活动 - 401 AAD 身份验证失败