美文网首页
iOS10 Swift3.0 UICollectionView点

iOS10 Swift3.0 UICollectionView点

作者: 再来一份果子狸 | 来源:发表于2017-01-23 18:13 被阅读189次

很多教程用到了
let cell = collectionView.cellForItem(at: indexPath)
这个其实是不对的,因为这个只适合于背景变色,而且数量不能太多,不能超过CollectionView的缓存范围,所以,如果要正确使用,我建议各位在数据模型中改变!
在数据模型中设立Selected:Bool
然后在返回Cell中进行判断

利用
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { Tags[indexPath.row].selected = true } func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) { Tags[indexPath.row].selected = false tagscolltionView?.reloadData()
这样才能够真正的改变字体颜色,切在重用Cell的时候不会乱。

相关文章

网友评论

      本文标题:iOS10 Swift3.0 UICollectionView点

      本文链接:https://www.haomeiwen.com/subject/triabttx.html