我希望能够将图像和视频加载到我的UICollectionView。
这是我的解析查询代码:
var arrayOfDetails = [Details]()
func queryFromParse(){
let query = PFQuery(className: "currentUploads")
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in
if error == nil
{
if let newObjects = objects as? [PFObject] {
for oneobject in newObjects {
let text = oneobject["imageText"] as! String
let username = oneobject["username"] as! String
let objID = oneobject.objectId!
let time = oneobject.createdAt!
let likedBy = oneobject["likedBy"] as! NSArray
let comments = oneobject["comments"] as! NSArray
if let userImage = oneobject["imageFile"] as? PFFile {
let userImage = oneobject["imageFile"] as! PFFile
let imageURL = userImage.url
let OneBigObject = Details(username: username, text: text, CreatedAt: time, image: imageURL!, objID: objID, likedBy: likedBy, comments: comments)
self.arrayOfDetails.append(OneBigObject)
dispatch_async(dispatch_get_main_queue()) { self.collectionView.reloadData() }
}
}
}
}
}
}
我的结构细节:
struct Details {
var username:String!
var text:String!
var CreatedAt:NSDate!
var image:String!
var objID:String!
var likedBy:NSArray
var comments:NSArray
init(username:String,text:String,CreatedAt:NSDate,image:String,objID:String,likedBy:NSArray,comments:NSArray){
self.username = username
self.text = text
self.CreatedAt = CreatedAt
self.image = image
self.objID = objID
self.likedBy = likedBy
self.comments = comments
}
}
在我的cellForItemAtIndexPath
我使用let post = self.arrayOfDetails[indexPath.row]
来获取当前对象,但我在这里遇到了一些问题。在解析中,我将图像存储为文件,名称为“uploaded_image.png”,视频存储为文件,名称为“uploaded_video.mp4”。如果文件是“uploaded_image.png”,如何在UICollectionViewCell中创建UIImageView,如果文件是“uploaded_video.mp4”,我如何在视频播放器中创建?
或其他任何建议?