Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift 1.2,如何从Parse1.7中正确检索图像?_Ios_Image_Swift_Parse Platform_Tableview - Fatal编程技术网

Ios Swift 1.2,如何从Parse1.7中正确检索图像?

Ios Swift 1.2,如何从Parse1.7中正确检索图像?,ios,image,swift,parse-platform,tableview,Ios,Image,Swift,Parse Platform,Tableview,虽然所有不同的存储都存储在Parse中,但所有配置文件图片都作为相同的图像加载 请帮助我。您正在设置当前登录用户的照片,请在cellForRowAtIndexPath中设置用户?[“照片”] // import UIKit import Parse import Foundation class EditFriendsController: UITableViewController { var allUsers:NSArray = [] // NSArray *allUsers

虽然所有不同的存储都存储在Parse中,但所有配置文件图片都作为相同的图像加载


请帮助我。

您正在设置当前登录用户的照片,请在cellForRowAtIndexPath中设置用户?[“照片”]

// import UIKit
import Parse
import Foundation

class EditFriendsController: UITableViewController {

    var allUsers:NSArray = [] // NSArray *allUsers
    var currentUser = PFUser.currentUser()
    var friends:NSMutableArray = [] // used in FriendsController
    var profileImages = [PFFile]()

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        // PFQuery *query = [PFUser query] in objective C
        var query = PFUser.query()
        query!.orderByAscending("username")
        query!.findObjectsInBackgroundWithBlock {
            (objects: [AnyObject]?, error: NSError?) -> Void in
            if error != nil {
                // Log details of the failure
                println("Error: \(error!)\(error!.userInfo)")
            } else {
                // The find succeeded.
                println("Successfully retrieved \(objects!.count) scores.")
                self.allUsers = objects!
                // println("\(self.allUsers)")
                self.animateTable() // include self.tableView.reloadData()
            }
        }
        self.currentUser = PFUser.currentUser()
    }

    // MARK: - Table view animate function
    func animateTable() {
        tableView.reloadData()

        let cells = tableView.visibleCells()
        let tableHeight:CGFloat = tableView.bounds.size.height

        for transformBefore in cells {
            let cell: UITableViewCell = transformBefore as! UITableViewCell
            cell.transform = CGAffineTransformMakeTranslation(0, tableHeight)
        }        
        var index = 0

        for transformAfter in cells {
            let cell: UITableViewCell = transformAfter as! UITableViewCell
            UIView.animateWithDuration(1.5, delay: 0.05 * Double(index), usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: nil, animations: { () -> Void in
                cell.transform = CGAffineTransformMakeTranslation(0, 0)
            }, completion: nil)

            index += 1
        }
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {        
        return 1
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.allUsers.count
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! EditFriendsProfileViewCell

        var user = self.allUsers[indexPath.row] as! PFUser
        cell.usernameLabel.text = user.username!

        // cell.profileImageView.image = UIImage(named: profileImages[indexPath.row])
        if let userPicture = PFUser.currentUser()?["photo"] as? PFFile {
            userPicture.getDataInBackgroundWithBlock({
                (imageData:NSData?, error:NSError?) -> Void in
                var img:UIImageView = UIImageView()
                if (error == nil) {
                    cell.profileImageView.image = UIImage(data: imageData!)    
                } else {

                }
            })
        }

    // image cornerRadius

        cell.profileImageView.layer.cornerRadius = 10
        cell.profileImageView.clipsToBounds = true

        var myFriend = isFriend(user)

        cell.accessoryType = myFriend ? .Checkmark : .None
        //cell.checkImageView.image = myFriend ? UIImage(named: "checkedFilled.png") : UIImage(named: "checkedWhite.png")
        return cell
    }

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        self.tableView.deselectRowAtIndexPath(indexPath, animated: false)
        var cell = tableView.cellForRowAtIndexPath(indexPath) as! EditFriendsProfileViewCell
        var user = self.allUsers[indexPath.row] as! PFUser
        var friendsRelation = self.currentUser!.relationForKey("friendsRelation")
        var myFriend = isFriend(user)
        if (myFriend) {
            // remove process
            // 1. Remove the checkmark
            cell.accessoryType = UITableViewCellAccessoryType.None
            // cell.imageView?.image = UIImage(named: "checkedWhite.png")
            // 2. Remove from array of friend
            var friend = PFUser()
            for friend in self.friends  {
                if friend.objectId == user.objectId {
                    self.friends.removeObject(friend)
                    break;
                }
            }
            // 3. Remove from the backend
            friendsRelation.removeObject(user)
        } else {
            // add them
            cell.accessoryType = UITableViewCellAccessoryType.Checkmark
            // cell.imageView?.image = UIImage(named: "checkedFilled.png")
            self.friends.addObject(user)
            friendsRelation.addObject(user)
        }
        self.currentUser!.saveInBackgroundWithBlock {
            (success: Bool, error: NSError?) -> Void in
            if (success) {
                // The post has been added to the user's likes relation.
            } else {
                // There was a problem, check error.description
                println("Error: \(error!)\(error!.userInfo)")
            }
        }
    }

    // MARK: - Table view Helper Methods
    func isFriend(user: PFUser!) -> Bool {
        var friend = PFUser()
        for friend in self.friends  {
            if friend.objectId == user.objectId {
                return true;
            }
        }
        return false;
    }
}

您正在设置当前登录用户的照片,请在cellForRowAtIndexPath中设置用户?[“照片”]

// import UIKit
import Parse
import Foundation

class EditFriendsController: UITableViewController {

    var allUsers:NSArray = [] // NSArray *allUsers
    var currentUser = PFUser.currentUser()
    var friends:NSMutableArray = [] // used in FriendsController
    var profileImages = [PFFile]()

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        // PFQuery *query = [PFUser query] in objective C
        var query = PFUser.query()
        query!.orderByAscending("username")
        query!.findObjectsInBackgroundWithBlock {
            (objects: [AnyObject]?, error: NSError?) -> Void in
            if error != nil {
                // Log details of the failure
                println("Error: \(error!)\(error!.userInfo)")
            } else {
                // The find succeeded.
                println("Successfully retrieved \(objects!.count) scores.")
                self.allUsers = objects!
                // println("\(self.allUsers)")
                self.animateTable() // include self.tableView.reloadData()
            }
        }
        self.currentUser = PFUser.currentUser()
    }

    // MARK: - Table view animate function
    func animateTable() {
        tableView.reloadData()

        let cells = tableView.visibleCells()
        let tableHeight:CGFloat = tableView.bounds.size.height

        for transformBefore in cells {
            let cell: UITableViewCell = transformBefore as! UITableViewCell
            cell.transform = CGAffineTransformMakeTranslation(0, tableHeight)
        }        
        var index = 0

        for transformAfter in cells {
            let cell: UITableViewCell = transformAfter as! UITableViewCell
            UIView.animateWithDuration(1.5, delay: 0.05 * Double(index), usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: nil, animations: { () -> Void in
                cell.transform = CGAffineTransformMakeTranslation(0, 0)
            }, completion: nil)

            index += 1
        }
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {        
        return 1
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.allUsers.count
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! EditFriendsProfileViewCell

        var user = self.allUsers[indexPath.row] as! PFUser
        cell.usernameLabel.text = user.username!

        // cell.profileImageView.image = UIImage(named: profileImages[indexPath.row])
        if let userPicture = PFUser.currentUser()?["photo"] as? PFFile {
            userPicture.getDataInBackgroundWithBlock({
                (imageData:NSData?, error:NSError?) -> Void in
                var img:UIImageView = UIImageView()
                if (error == nil) {
                    cell.profileImageView.image = UIImage(data: imageData!)    
                } else {

                }
            })
        }

    // image cornerRadius

        cell.profileImageView.layer.cornerRadius = 10
        cell.profileImageView.clipsToBounds = true

        var myFriend = isFriend(user)

        cell.accessoryType = myFriend ? .Checkmark : .None
        //cell.checkImageView.image = myFriend ? UIImage(named: "checkedFilled.png") : UIImage(named: "checkedWhite.png")
        return cell
    }

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        self.tableView.deselectRowAtIndexPath(indexPath, animated: false)
        var cell = tableView.cellForRowAtIndexPath(indexPath) as! EditFriendsProfileViewCell
        var user = self.allUsers[indexPath.row] as! PFUser
        var friendsRelation = self.currentUser!.relationForKey("friendsRelation")
        var myFriend = isFriend(user)
        if (myFriend) {
            // remove process
            // 1. Remove the checkmark
            cell.accessoryType = UITableViewCellAccessoryType.None
            // cell.imageView?.image = UIImage(named: "checkedWhite.png")
            // 2. Remove from array of friend
            var friend = PFUser()
            for friend in self.friends  {
                if friend.objectId == user.objectId {
                    self.friends.removeObject(friend)
                    break;
                }
            }
            // 3. Remove from the backend
            friendsRelation.removeObject(user)
        } else {
            // add them
            cell.accessoryType = UITableViewCellAccessoryType.Checkmark
            // cell.imageView?.image = UIImage(named: "checkedFilled.png")
            self.friends.addObject(user)
            friendsRelation.addObject(user)
        }
        self.currentUser!.saveInBackgroundWithBlock {
            (success: Bool, error: NSError?) -> Void in
            if (success) {
                // The post has been added to the user's likes relation.
            } else {
                // There was a problem, check error.description
                println("Error: \(error!)\(error!.userInfo)")
            }
        }
    }

    // MARK: - Table view Helper Methods
    func isFriend(user: PFUser!) -> Bool {
        var friend = PFUser()
        for friend in self.friends  {
            if friend.objectId == user.objectId {
                return true;
            }
        }
        return false;
    }
}

错误是什么?在你的代码中哪里发生了这种情况?错误是所有配置文件图片都作为一个单独的图像加载,我想我错过了在查询语句中添加一些内容,但不是很确定..你正在设置当前用户的照片,设置用户?[“photo”]在CellForRowatinexpathy中,我明白了,是的,我猜图片来自当前用户的图片,但不知道为什么只填充当前用户的图片。谢谢你:D你节省了我的时间:D,刚刚改变了,工作得很好:D,谢谢,穆罕默德·阿德南把答案记下来。它可能会在将来帮助其他人。错误是什么?在你的代码中哪里发生了这种情况?错误是所有配置文件图片都作为一个单独的图像加载,我想我错过了在查询语句中添加一些内容,但不是很确定..你正在设置当前用户的照片,设置用户?[“photo”]在CellForRowatinexpathy中,我明白了,是的,我猜图片来自当前用户的图片,但不知道为什么只填充当前用户的图片。谢谢你:D你节省了我的时间:D,刚刚改变了,工作得很好:D,谢谢,穆罕默德·阿德南把答案记下来。它将来可能会帮助别人。