Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 错误:静态成员copyWithZone不能用于UIImageView类型的实例_Ios_Swift_Uiimageview_Uicollectionview - Fatal编程技术网

Ios 错误:静态成员copyWithZone不能用于UIImageView类型的实例

Ios 错误:静态成员copyWithZone不能用于UIImageView类型的实例,ios,swift,uiimageview,uicollectionview,Ios,Swift,Uiimageview,Uicollectionview,我需要声明一个图像,以便在下面的代码中使用它来将其设置为节背景,但它给了我一个错误 class MDCollectionViewLayoutAttributes : UICollectionViewLayoutAttributes { var color: UIColor = UIColor.whiteColor() var image : UIImageView! override func copyWithZone(zone: NSZone) -> AnyOb

我需要声明一个图像,以便在下面的代码中使用它来将其设置为节背景,但它给了我一个错误

class MDCollectionViewLayoutAttributes : UICollectionViewLayoutAttributes
{
    var color: UIColor = UIColor.whiteColor()
    var image : UIImageView!

    override func copyWithZone(zone: NSZone) -> AnyObject
    {
        let newAttributes: MDCollectionViewLayoutAttributes = super.copyWithZone(zone) as! MDCollectionViewLayoutAttributes
        newAttributes.color = self.color.copyWithZone(zone) as! UIColor
        newAttributes.image = UIImageView(frame:newAttributes.bounds)
        newAttributes.image.image = UIImage(named:"Appetizer.png")

        newAttributes.image = self.image.copyWithZone(zone) as! UIImageView// this is giving me an error
        return newAttributes
    }
}

有什么帮助吗?

UIImageView不符合NSCopying协议,这就是copyWithZone无法工作的原因。您可以创建UIImageView或其子类的扩展,在其中实现NSCopying一致性。

UIImageView不符合NSCopying协议,这就是copyWithZone不起作用的原因。您可以创建UIImageView或其子类的扩展,在其中实现NSCopying一致性。

有没有任何示例?或者任何一个例子的链接?有任何例子吗?或者以任何链接为例?
override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]?
{
    let attributes = super.layoutAttributesForElementsInRect(rect)
    var allAttributes = [UICollectionViewLayoutAttributes]()

    if let attributes = attributes
    {

        for attr in attributes
        {
            if (attr.representedElementCategory == UICollectionElementCategory.Cell && attr.frame.origin.x == self.sectionInset.left)
            {
                                   let decorationAttributes = SBCollectionViewLayoutAttributes(forDecorationViewOfKind: "sectionBackground", withIndexPath: attr.indexPath)

              //  decorationAttributes.color = UIColor.brownColor().colorWithAlphaComponent(1)