UICollectionView使用reloadData()方法之后,Cell 里面的控件报错找不到
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{
NSLog("\(indexPath.row)")
let collectionCell = collectionView.dequeueReusableCellWithReuseIdentifier("collectionCellLocation", forIndexPath: indexPath) as UICollectionViewCell
let cityLocationButton = collectionCell.viewWithTag(1) as! UIButton
let autoLocationButton = collectionCell.viewWithTag(2) as! UIButton
if indexPath.row > 0 {
NSLog("1111111")
autoLocationButton.hidden = true
cityLocationButton.setTitle(searchCityList[indexPath.row-1], forState: UIControlState.Normal)
}else{
cityLocationButton.hidden = true
}
//添加手动定位点击事件
cityLocationButton.tag = indexPath.row
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "clickForCityName:")
cityLocationButton.addGestureRecognizer(tapGestureRecognizer)
//添加自动定位点击事件
autoLocationButton.tag = indexPath.row
autoLocationButton.addTarget(self, action: "clickAutoLocation:", forControlEvents: UIControlEvents.TouchUpInside)
return collectionCell
}
刚进来的时候可以正常显示控件,但是reloadData()之后,就报错:
let cityLocationButton = collectionCell.viewWithTag(1) as! UIButton
这一行显示错误信息是:fatal error: unexpectedly found nil while unwrapping an Optional value
望大神们解答
...全文
相关推荐
UICollectionView自适应cell不同大小
UICollectionView不同cell大小自适应
iOS UICollectionView刷新时闪屏的解决方法
本篇文章主要介绍了iOS UICollectionView刷新时闪屏的解决方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
关于UICollectionView横向滑动分页的问题
关于UICollectionView的contentSize为什么不起作用
UICollectionView的基础用法
Demo中描述了UICollectionView的基础用法,代码可以帮助初学者清楚的了解方法的作用
详解ios监听reloadData刷新列表完毕的时机
主要介绍了详解ios监听reloadData刷新列表完毕的时机,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧


