UICollectionView使用reloadData()方法之后,Cell 里面的控件报错找不到
来源:互联网 发布:组装机 知乎 编辑:程序博客网 时间:2024/05/10 12:50
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
望大神们解答
0 0
- UICollectionView使用reloadData()方法之后,Cell 里面的控件报错找不到
- UICollectionView使用reloadData()方法之后,Cell 里面的控件报错找不到
- 如何在UICollectionView reloadData后找到的某个cell
- 如何在UICollectionView reloadData后找到的某个cell
- 如何在UICollectionView reloadData后找到的某个cell
- collectionView reloadData 之后 cell消失
- iOS 关于UICollectionView选中状态,当使用reloadData方法时出现数据的问题?
- iOS开发~为UICollectionView的reloadData方法添加动画
- 防止cell里面的子控件重叠方法
- UICollectionView reloadData不走cellForRowAtIndexPath的问题
- UICollectionView reloadData不走cellForRowAtIndexPath的问题
- iOS UICollectionView reloadData后找到某个cell 更新某个cell数据
- cell里面控件宽度布局的问题
- UICollectionView使用Xib自定义cell
- UITableView使用reloadData的几种动画方法
- swift中UICollectionView的使用(headerview/footerview/cell/model)
- UICollectionView reloadData无法更新的奇怪问题。(更新)
- UITableView reloadData的正确方法
- UITableViewController设置背景图片问题
- 我的2016—遇见自己,遇见未来
- Shell 传递参数
- UICollectionView滚动到指定cell的机制问题
- 如何利用ROS MoveIt快速搭建机器人运动规划平台?
- UICollectionView使用reloadData()方法之后,Cell 里面的控件报错找不到
- next 跳过当前循环
- cocoapod装的库什么还没法子import
- Shell 数组
- 进程与线程的一个简单解释
- 求助----关于来电界面修改的越狱开发
- /bin,/sbin,/usr/sbin,/usr/bin 目录的区别
- 程序员专属:chrome 定制属于自己的百度主题
- LayaAir引擎学习日志5----LayaAir IDE创建TS项目并详解目录结构