'UICollectionViewCell'没有名为'image'的成员[Swift]

加布里埃尔·比滕库特(Gabriel Bitencourt)

我正在建立一个带有的项目,该项目UICollectionView显示带有标签的图像。我创建了ViewControllerCellViewController,就像它应该做的那样。

CellViewController代码中如下所示:

class CellController: UICollectionViewCell {

    @IBOutlet weak var image: UIImageView!
    @IBOutlet weak var label: UILabel!


}

但是,ViewController当我设置图像时,它给了我错误。这是代码:

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

    let cell: UICollectionViewCell = collection.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CellController

    cell.image.image = UIImage(named: "star")

    return cell
}

最奇怪的是,我有一个从GitHub下载的项目,该项目与我的项目基本相同,并且运行良好。

提前致谢!

伊恩

你的问题是:UICollectionViewCell尽管您将单元格CellController强制转换为类型UICollectionViewCell,但该类型没有image属性。删除它或将其替换CellController将解决您的问题。

let cell = collection.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CellController

我也考虑将您的图片视图重命名为imageView关于这条线cell.image.image有些东西看起来不正确!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Swift'没有名为的成员'

Swift ViewController没有名为的成员

没有名为的成员

Swift-桥接头失败。“ *”没有名为“ *”的成员

Swift-'String'没有名为'isEqualToString'的成员

Swift'WKInterfaceLabel'没有名为'text'的成员

'[细绳]?' 在Swift中没有名为“ count”的成员

Swift 1.2 [AnyObject]没有名为'objectForKey'的成员

Swift NSURLConnection没有名为start的成员

Swift'String.Type'没有名为'stringWithContentsOfFile'的成员

Swift:'((NSObject,AnyObject)'没有名为'subscript'的成员

swift uiview没有名为center的成员

SWIFT字符串?没有名为“ element”的成员

“ NSURLRequest?” 没有名为“ URL”的成员-Swift

模块“Swift”没有名为“Task”的成员

Swift数组“对象”没有名为下标的成员

Swift SpriteKit:“ MCTFruit没有名为append的成员吗?

“ UINavigationController?” 没有名为“ popToRootViewControllerAnimated”的成员

[AnyObject]?没有名为“下标”的成员

NSURLResponse没有名为allHeaderFields的成员

UIButton没有名为“ target”的成员

UIView没有名为'delegate的成员

UIView没有名为“ setTranslatesAutoresizingMaskIntoConstraints”的成员

AnyObject没有名为“ sort”的成员

斯威夫特:没有名为的成员

UIPanGestureRecognizer没有名为touchesBegan的成员

NSEntityDescription没有名为“ name”的成员

AnyObject?没有名为“ objectAtIndex”的成员

“ AppDelegate”没有名为“ managedObjectContext”的成员