UIImage的?与UIImage不同

时间:2015-08-06 06:45:52

标签: ios swift uiscrollview uiimage

我正在尝试将3个图像存储在一个数组中,然后在ScrollView中显示它们,但它在这一行中显示了这个错误:" self.paginatedScrollView?.images = images"

override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)

        displayPost(post)

        paginatedScrollView = PaginatedScrollView(frame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height))
        self.view.addSubview(paginatedScrollView!) // add to the

        let images = [ post!.image1.value,  post!.image2.value, post!.image3.value]

        self.paginatedScrollView?.images = images
    }

1 个答案:

答案 0 :(得分:2)

这是因为UIImage?是可选的。您只需要打开图像的值,然后再使用它们进行分配!操作

试试这个:

let images: [UIImage] = [ (post!.image1.value)!,  (post!.image2.value)!, (post!.image3.value)!]

编辑:您之前创建的阵列是保存选项。所以我只是通过添加一个'来解开你在数组中保存的所有值!'。在此处阅读有关选项的内容:http://www.touch-code-magazine.com/swift-optionals-use-let/