Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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
Image 如何在解析中获取图像,单元格名称起作用,但图像不加载_Image_Swift_Parsing_Get_Tableview - Fatal编程技术网

Image 如何在解析中获取图像,单元格名称起作用,但图像不加载

Image 如何在解析中获取图像,单元格名称起作用,但图像不加载,image,swift,parsing,get,tableview,Image,Swift,Parsing,Get,Tableview,我可以从parse加载图像,但它们有一个代码名,我想在单元格中显示图像,不要加载图像 // import UIKit import Parse import Bolts class LojasViewController: UIViewController, UITableViewDelegate { var ParseData = [PFObject]() var ParseImages = [PFFile]() @IBOutlet weak var saloesT

我可以从parse加载图像,但它们有一个代码名,我想在单元格中显示图像,不要加载图像

//
import UIKit
import Parse
import Bolts

class LojasViewController: UIViewController, UITableViewDelegate {
    var ParseData = [PFObject]()
    var ParseImages = [PFFile]()

    @IBOutlet weak var saloesTableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Retrieving Parse Information
        var query = PFQuery(className:"Saloes")
        query.orderByAscending("nome")
        query.findObjectsInBackgroundWithBlock {
            (objects: [AnyObject]?, error: NSError?) -> Void in

            if error == nil {
                // The find succeeded.
                println(objects!.count)

                // Do something with the found objects
                if let objects = objects as? [PFObject] {
                    self.ParseData = objects

                    println(self.ParseData.count)
                    self.saloesTableView.reloadData()
                    for object in objects {

                        println(object["nome"])
                        println(object["cidade"])
                        println(object["imagemCelula"])
                        println(object["endereco"])
                        println(object["GeoPonto"])
                        println(object["telefone"])
                        println(object["celular"])
                        println(object["texto"])
                        println(object["Imagem1"])
                        println(object["Imagem2"])
                        println(object["Imagem3"])
                        println(object["Imagem4"])
                        println(object["Imagem5"])
                        println(object["Imagem6"])
                        println(object["Imagem7"])
                        println(object["Imagem8"])
                        println(object["Imagem9"])
                        }
                    }
                } else {

                // Log details of the failure
                println("Error: \(error!) \(error!.userInfo!)")
            }
        }
        }

override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // Esconde statusBar
    override func prefersStatusBarHidden() -> Bool {
        return true
    }

    @IBAction func voltarButton(sender: AnyObject) {
        self.dismissViewControllerAnimated(true, completion: nil)
    }

    func loadData () {
    }

    // MARK: - Table view data source ____________________________________

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

    func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int
    {
        return ParseData.count
    }

    func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell?
    {
        let cell:SaloesTableViewCell = tableView!.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath!) as! SaloesTableViewCell

            cell.nomeSalao.text = ParseData[indexPath!.row]["nome"] as? String

            let imagemCelula = ParseData[indexPath!.row]["imagemCelula"] as! PFFile

        return cell
    }

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

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    }
}

您可以使用FindObjectsInBackgroundithBlock获取解析对象。但是,一旦获得图像的解析对象,就需要通过调用getDataInBackgroundWithBlock下载实际文件

这是您的代码:

我更新了ParseImages,它现在是一个NSData数组

我实现了GetDataInBackgroundithBlock

我为imagemCelula分配了一个UIImage,该UIImage来自您从Parse检索到的图像

让我知道它是如何工作的

import UIKit
import Parse
import UIKit
import Parse
import Bolts

class LojasViewController: UIViewController, UITableViewDelegate {
var ParseData = [PFObject]()
var ParseImages: [NSData] = []

@IBOutlet weak var saloesTableView: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()

    // Retrieving Parse Information
    var query = PFQuery(className:"Saloes")
    query.orderByAscending("nome")
    query.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]?, error: NSError?) -> Void in

        if error == nil {
            // The find succeeded.
            println(objects!.count)

            // Do something with the found objects
            if let objects = objects as? [PFObject] {
                self.ParseData = objects

                println(self.ParseData.count)
                self.saloesTableView.reloadData()
                for object in objects {
                    object.getDataInBackgroundWithBlock({ (parseImageData, error) -> Void in
                if (error == nil) {
                    let thatImageData: NSData = parseImageData
                    ParseImages.append(thatImageData)

                        println(object["nome"])
                        println(object["cidade"])
                        println(object["imagemCelula"])
                        println(object["endereco"])
                        println(object["GeoPonto"])
                        println(object["telefone"])
                        println(object["celular"])
                        println(object["texto"])
                        println(object["Imagem1"])
                        println(object["Imagem2"])
                        println(object["Imagem3"])
                        println(object["Imagem4"])
                        println(object["Imagem5"])
                        println(object["Imagem6"])
                        println(object["Imagem7"])
                        println(object["Imagem8"])
                        println(object["Imagem9"])
} else {
println("failed to load images")
}
                        }
                    }
                } else {
            // Log details of the failure
            println("Error: \(error!) \(error!.userInfo!)")
        }
    }
    }

override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

// Esconde statusBar
override func prefersStatusBarHidden() -> Bool {
    return true
}

@IBAction func voltarButton(sender: AnyObject) {
    self.dismissViewControllerAnimated(true, completion: nil)
}

func loadData () {
}

// MARK: - Table view data source ____________________________________

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

func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int
{
    return ParseData.count
}

func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell?
{
    let cell:SaloesTableViewCell = tableView!.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath!) as! SaloesTableViewCell

        cell.nomeSalao.text = ParseData[indexPath!.row]["nome"] as? String

        let imagemCelula = UIImage(data: ParseImages[indexPath!.row])

    return cell
}

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

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
}
}

谢谢昆汀,非常有用!现在我将修复object.getDataInBackgroundithBlock和伟大的KKKK