简体   繁体   English

使用swift从parse.com查询数据和图像到tableview

[英]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. 我正在寻找使用swift将数据和图像查询到表格视图中的方法,但是,我似乎找不到任何教程或任何显示方法的东西。 In my parse class I have a class named Products and in that class I have a column called productName , productImage , and productDescription . 在我的解析类中,我有一个名为Products的类,在该类中,我有一个名为productNameproductImageproductDescription Than in my table view I have it where it shows the Image and the productName . 在我的表格视图中,它比在其中显示Image和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. 相比之下,当您单击单元格查询到viewController上以在TextView中显示Image,名称和描述时,它就比想象中的要好。 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. 更新:我可以显示我的图片,但在正确的类中没有UIImage。 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 这是我发布的图片:vvvvvv很确定我必须在此处添加一些内容,但不确定从表视图中选择产品时如何查询图片

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. 看看: https : //parse.com/docs/ios/guide#user-interface-pfquerytableviewcontroller ,这是Parses自己的用户界面,可从解析查询生成表视图。 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! 我希望这有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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