ios - 在特定的 CollectionViewCell 中隐藏 View

标签 ios xcode swift storyboard collectionview

我对如何以正确的方式实现这些东西有疑问。 到此为止

if indexPath.row == 1 {
            let indexPatha = NSIndexPath(forRow: 0, inSection: 0)

            let changeCell = collectionView .cellForItemAtIndexPath(indexPatha) as! BarCollectionViewCell
            changeCell.addNewBottleSecondButton.alpha = 0
}

但是当我滑动直到单元格被隐藏时,我收到错误消息,在展开可选值时意外发现 nil,而且这看起来仍然不像我想要的那样。 我想实现这一点,当我有多个单元格时,我想隐藏一个特定 View 。

最佳答案

在您的流程中,改为在 cellForRowAtIndexPath 中处理此问题是否可行?

初始化单元格后:

    cell.addNewBottleSecondButton.hidden = (indexPath.row == 0) && (dataItems.count > 1)

关于ios - 在特定的 CollectionViewCell 中隐藏 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36066297/

相关文章:

ios - 与 iOS 联系人集成

android - 强制IOS/android用户查看通知

iphone - 更改 UINavigationController 推送动画的持续时间

arrays - 如何链接结构?需要优化性能

ios - 3d touch swift 3 不打开viewcontroller

ios - 如何更改 URL iOS 中的参数

ios - 控制台数据问题

ios - 如何在 Interface Builder 中将 Subview 添加到 UIButton

ios - 使用应用程序加载器的 Xcode 5 ios 应用程序提交错误

swift - 以编程方式移动到下一个 View Controller