ios - 如何在每次点击更新的条件下禁用特定 CollectionViewCell 的用户交互
问题描述
每个单元格都是一个结构,其中包含一个变量:numberOfRegistration。
如果用户单击该单元格,则 numberOfRegistration 将 +1。
如果 counter = 5 或更多,则单元格的用户交互将被禁用。
我以某种方式想出了这个,但它没有用。
struct hourSlot{
var hoursService:String
var numberOfRegistration:Int = 0
var isDisable:Bool = false
mutating func disable(){
if numberOfRegistration >= 5{
isDisable = true
}
}
}
在 cellForItemAt 中:
var isDisableCell = hoursArray[indexPath.item].isDisable
if isDisableCell{
cell.isUserInteractionEnabled = false
}
注意: hoursArray 是一个包含结构的数组。
解决方案
尝试这个:
let hourSlot = hoursArray[indexPath.item]
hourSlot.disable()
if hourSlot.isDisable{
cell.isUserInteractionEnabled = false
}
为了改变 isDisable 你需要调用 disable() 方法。然后你可以检查它的变量。
推荐阅读
- angular - Nebular - 如何在 `getConfigValue()` 中注入自定义策略验证?
- python - 函数执行前打印的输出
- git - 将 Github 存储库的子文件夹同步到单独的 github 存储库
- python - Python Selenium Webdriver/Chromedriver(附加的设备无法正常工作......)
- javascript - 如何使用 Javascript 修改响应(替换字符串)?
- spring-boot - kafka SASL_PLAIN SCRAM 在春季启动消费者中失败
- python - 如何使用用户输入来创建类的实例?
- graphics - VK_ACCESS_COLOR_ATTACHMENT_READ_BIT 的实际使用
- java - Micronaut Swagger 重定向不适用于带有授权码 + PKCE 的 OAuth 2
- r - 如何在R中加载()和查看()函数参数[即函数(x)]