gpt4 book ai didi

ios - 从指针接收图像

转载 作者:行者123 更新时间:2023-11-30 14:10:34 26 4
gpt4 key购买 nike

我的解析中有一个指针。指针告诉我谁上传了这些图像。我正在尝试检索上传者的用户名和个人资料图片。为此,我放置了 query.includeKey("uploader") 。用户通过用户类别进行管理。帖子是在 posts 类中管理的。要检索图像和名称,我有以下代码。

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

let cell = collectionView.dequeueReusableCellWithReuseIdentifier("newview", forIndexPath: indexPath) as! NewCollectionViewCell
let item = self.votes[indexPath.row]





// Display "initial" flag image
var initialThumbnail = UIImage(named: "question")
cell.postsImageView.image = initialThumbnail

if let pointer = item["uploader"] as? PFObject {
cell.userName!.text = item["username"] as? String

}

if let profile = item["uploader"] as? PFObject {

cell.profileImageView.loadInBackground({ (image:UIImage, error:NSError) -> Void in
if error != nil{
cell.profileImageView.image = image
}
})}

if let votesValue = item["votes"] as? Int
{
cell.votesLabel?.text = "\(votesValue)"
}

// Fetch final flag image - if it exists
if let value = item["imageFile"] as? PFFile {

cell.postsImageView.file = value
cell.postsImageView.loadInBackground({ (image: UIImage?, error: NSError?) -> Void in
if error != nil {
cell.postsImageView.image = image
}
})
}

return cell
}

但是发生错误,表明无法使用 (UIImage, NSError)->void 类型的参数列表调用 loadinbackround。奇怪的是,错误仅发生在我尝试为用户检索图像的第一部分。我真的陷入困境并需要帮助。我的指针检索错误吗?谢谢。

更新2

@IBOutlet weak var collectionView: UICollectionView!

override func viewDidLoad() {
super.viewDidLoad()



let query = PFQuery(className: "Posts")
query.includeKey("pointName")
query.findObjectsInBackgroundWithBlock{(question:[AnyObject]?,error:NSError?) -> Void in

if error == nil
{
if let allQuestion = question as? [PFObject]
{
self.votes = allQuestion
self.collectionView.reloadData()
}
}
}


// Wire up search bar delegate so that we can react to button selections

// Resize size of collection view items in grid so that we achieve 3 boxes across

loadCollectionViewData()
}

/*
==========================================================================================
Ensure data within the collection view is updated when ever it is displayed
==========================================================================================
*/

// Load data into the collectionView when the view appears
override func viewDidAppear(animated: Bool) {
loadCollectionViewData()
}

/*
==========================================================================================
Fetch data from the Parse platform
==========================================================================================
*/

func loadCollectionViewData() {
// Build a parse query object
}

/*
==========================================================================================
UICollectionView protocol required methods
==========================================================================================
*/

func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.votes.count
}



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

let cell = collectionView.dequeueReusableCellWithReuseIdentifier("newview", forIndexPath: indexPath) as! NewCollectionViewCell
let item = self.votes[indexPath.row]





// Display "initial" flag image
var initialThumbnail = UIImage(named: "question")
cell.postsImageView.image = initialThumbnail

if let pointer = item["uploader"] as? PFObject {
cell.userName!.text = item["username"] as? String
print("username")

}

if let profile = item["uploader"] as? PFObject,
profileImageFile = profile["profilePicture"] as? PFFile {
cell.profileImageView.file = profileImageFile
cell.profileImageView.loadInBackground { image, error in
if error == nil {
cell.profileImageView.image = image
}
}
}

if let votesValue = item["votes"] as? Int
{
cell.votesLabel?.text = "\(votesValue)"
}

// Fetch final flag image - if it exists
if let value = item["imageFile"] as? PFFile {
println("Value \(value)")
cell.postsImageView.file = value
cell.postsImageView.loadInBackground({ (image: UIImage?, error: NSError?) -> Void in
if error != nil {
cell.postsImageView.image = image
}
})
}

return cell
}

在我的课后类(class)中,它是这样的 enter image description here用户在用户类别中进行管理。我想获取发布该图像的人的个人资料图片和用户名。在用户类中我拥有所有用户信息。 enter image description here

最佳答案

cell.postsImageView.loadInBackground({
(image: UIImage!, error: NSError!) -> Void in
if error == nil {
if image != nil {
dispatch_async(dispatch_get_main_queue(),{
cell.postsImageView.image = image
})
}else{
println("Image not available")
}

}else{
println(Image Downloading error: \(error))
}
})

试试这个,我想这会对你有帮助:)

关于ios - 从指针接收图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31825203/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com