简体   繁体   中英

querying data and images into a tableview from parse.com using swift

在此处输入图片说明

I'm looking to query data and images into a tableview using swift but, I can't seem to find any tutorials or anything showing how to do it. In my parse class I have a class named Products and in that class I have a column called productName , productImage , and productDescription . Than in my table view I have it where it shows the Image and the productName . Than it's suppose to when you click on the cell query over to a viewController to show the Image, the name and the description in a textView. If someone could please give me a hand that would be much appreciated.!

    // Display product image
    var initialThumbnail = UIImage(named: "question")
    cell.ProductImage.image? = initialThumbnail!
    if let thumbnail = object?["productImage"] as? PFFile {
        cell.ProductImage.file = thumbnail
        cell.ProductImage.loadInBackground()
    }

It seems that there is something wrong with this code because when I run my app it shows just my question marked picture and not the image from parse.

Update: I was able to have my pictures show up i didn't have the UIImage in the right class. However I still can't get the image to show up with the other data in the view controller after you click on the cell. only the description and name show up. Any ideas?

This is for the image i posted:vvvvvv Pretty sure i have to add something here but not really sure what to get the image to query over when the product is selected from the table view

Update: Found out what the problem was. I added this code to it and it works now.

if let object = currentObject {
        productName.text = object["productName"] as? String
        productDescription.text = object["productDescription"] as! String var initialThumbnail = UIImage(named: "question")
        ProductImage.image? = initialThumbnail!
        if let thumbnail = object["productImage"] as? PFFile {
            ProductImage.file = thumbnail
            ProductImage.loadInBackground()

have a look at: https://parse.com/docs/ios/guide#user-interface-pfquerytableviewcontroller , this is Parses own user interface which produces a table view from a parse query. It also explains how you can add a thumbnail to the cell. Each cell will contain the object so you could easily segue to the image the cell represents. I hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM