簡體   English   中英

檢索個人資料圖片

[英]Retrieve Profile Image

我正在嘗試從解析中檢索用戶個人資料圖像。 我有一個收藏夾視圖,並且正在檢索人們發布的所有圖像。 我也想在單元格中顯示每個用戶的個人資料圖像。 我正在使用以下代碼覆蓋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
}

但是,我發現它會將配置文件圖像設置為當前用戶,而不是發布圖像的用戶。 我怎樣才能做到這一點? 謝謝

更新

所以在解析我的帖子課是 在此處輸入圖片說明

所以我知道是誰上傳的,但是我不知道如何檢索該特定用戶的個人資料圖片。

好的,這可能會幫助您實現Objective-C

PFUser *user = PFUser *user = [PFUser currentUser]; 
[user fetchIfNeededInBackgroundWithBlock:^(PFObject *object, NSError *error) {
 _profileImage.file = [object objectForKey:@"profilePicture"]; 
}];

您需要使用一個指向創建對象的用戶的指針。 個人資料照片應在用戶類別中。 然后,將指針包括在查詢中,這將返回用戶數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM