[英]How do I store images into UIImage array (Swift)
Here is my code 这是我的代码
self.pages?.photo1.getDataInBackgroundWithBlock {
(imageData: NSData?, error:NSError?) -> Void in
if error == nil {
let image = UIImage(data: imageData!)
println(image!)
self.pageImages.append(image!)
when I run a println(pageImages.count)
I get a 0 even though I know there are other elements in my dataset (pages) 当我运行println(pageImages.count)
即使我知道数据集中还有其他元素(页面),我也会得到0。
NOTE: "photo1" is stored in a dictionary as a PFFIle type 注意:“ photo1”作为PFFIle类型存储在字典中
and a println(image) displays the following result 并且println(image)显示以下结果
UIImage: 0x7f90f3e12df0, {748, 420}} UIImage:0x7f90f3e12df0,{748、420}}
The problem is that you cannot add an element to an array the way you did. 问题是您不能像以前那样将元素添加到数组中。
To add an element at the end, use 要在最后添加元素,请使用
pageItems.append(image)
To insert an element at the beginning, use 要在开头插入元素,请使用
pageItems.insert(image, atIndex: 0)
The following works as expected in Playground: 以下在Playground中可以正常使用:
var imageArray: [UIImage] = []
let image = UIImage()
imageArray.append(image)
imageArray.insert(image, atIndex: 0)
let x = imageArray.count // 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.