需求:
在一个collectionView组建中默认选中第一个item,当点击当前item时,当前item为选中状态,其他item为未选中状态。


实现思路:
当cell第一次在(0,0)位置赋值时,我设置默认选中,然后当点击其他位置的cell时,刷新(0,0)位置的cell为未选中状态。因为swift3之后取消了dispatch_once方法,所以只能用一个bool值开关退而求其次。




这样就能实现我的需求,不过我觉得这个方法太笨了,好的方法我暂时没有想到,有大佬有更简单的方式请指教~谢谢了
需求:
在一个collectionView组建中默认选中第一个item,当点击当前item时,当前item为选中状态,其他item为未选中状态。
实现思路:
当cell第一次在(0,0)位置赋值时,我设置默认选中,然后当点击其他位置的cell时,刷新(0,0)位置的cell为未选中状态。因为swift3之后取消了dispatch_once方法,所以只能用一个bool值开关退而求其次。
这样就能实现我的需求,不过我觉得这个方法太笨了,好的方法我暂时没有想到,有大佬有更简单的方式请指教~谢谢了
本文标题:UIColloctionView默认选中第一个item思路
本文链接:https://www.haomeiwen.com/subject/hyabiqtx.html
网友评论