![](/img/trans.png)
[英]hide a View from a single item in Row (collectionViewCell Item)
[英]Hide view in specific CollectionViewCell
我有疑問如何以正確的方式實現這些東西。 到目前為止我完成了
if indexPath.row == 1 {
let indexPatha = NSIndexPath(forRow: 0, inSection: 0)
let changeCell = collectionView .cellForItemAtIndexPath(indexPatha) as! BarCollectionViewCell
changeCell.addNewBottleSecondButton.alpha = 0
}
但是當我滑動直到隱藏單元格時,我收到錯誤,在解開一個 Optional 值時意外發現 nil,但這仍然不是我想要的方式。 我想實現這一點,當我有多個單元格時,我想隱藏一個特定視圖。
在您的流程中是否可以在 cellForRowAtIndexPath 中處理此問題?
初始化單元格后:
cell.addNewBottleSecondButton.hidden = (indexPath.row == 0) && (dataItems.count > 1)
如果單元格已從屏幕上滾動,由於 Apple 的出隊/重用優化,它可能不再存在。 以前遇到這個問題時,如果在嘗試更改單元格的 UI 時單元格不存在,我必須設置一個狀態變量並處理 cellForRow 中的 UI 更改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.