UICollectionView使用reloadData()方法之后,Cell 里面的控件报错找不到
2016-12-29 12:50
387 查看
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
望大神们解答
相关文章推荐
- Android开发中使用WebView控件显示找不到网页的解决方法
- 安装IE8在控制面板里面删除之后进不去桌面,提示找不到-IESetting.dll 解决办法(解决IE8卸载不了的问题,返回IE7 ,返回IE6),从IE8回到IE7的方法.
- Dev里面DataGid控件使用方法之一
- [iPhone开发之控件的使用]UIAlertView的各种属性、方法及代理的使用
- 【Android动态布局】之【使用addView方法时,如何保持已有动态控件位置不被改变】
- 常用控件的使用方法--(TextView/EditText/Button/Menu) -计算器代码
- 解决模板页使用的情况下,在内容页中使用 document.getElementById找不到控件的方法
- 如何解决FormView中实现DropDownList连动选择时出现 "Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用" 的错误
- [转自http://jhtchina.cnblogs.com/]Dev里面DataGid控件使用方法之一
- 使用addView方法时,如何保持已有动态控件位置不被改变
- 解决使用MasterPage后,Page.FindControl方法找不到指定控件的问题
- 解决使用MasterPage后,Page.FindControl方法找不到指定控件的问题
- 关于Asp.net的FormView控件中,用FindControl方法找不到对应控件问题
- 常见控件的使用方法 TextView EditText Button Menu
- Dev里面DataGid控件使用方法之一
- 关于Asp.net的FormView控件中,用FindControl方法找不到对应控件问题
- 使用addView方法时,如何保持已有动态控件位置不被改变
- Dev里面DataGid控件使用方法之一
- Dev里面DataGid控件使用方法之一
- [Android]在游戏的SurfaceView中获取输入与使用EditText,Spinner等控件的方法