簡體   English   中英

如何將圖像從解析加載到UIImage到UITableViewCell Swift中

[英]How to load image from parse to UIImage into a UITableViewCell Swift

我無法從解析中加載圖像。 大拇指叫做“問題”是可以的,但是當我嘗試從解析中加載圖像時,會發生錯誤並且應用程序崩潰

看一看:

import UIKit
class TableViewController: PFQueryTableViewController {

// Initialise the PFQueryTable tableview

    override init(style: UITableViewStyle, className: String!) {

        super.init(style: style, className: className)

    }

    required init!(coder aDecoder: NSCoder) {

        super.init(coder: aDecoder)

// Configure the PFQueryTableView

self.parseClassName = "Saude"

        self.textKey = "Nome"

self.pullToRefreshEnabled = true

self.paginationEnabled = false

    }

//    Define the query that will provide the data for the table view

    override func queryForTable() -> PFQuery {

        let query = PFQuery(className: "Saude")

        query.orderByAscending("Nome")

        return query

    }



    override func viewDidLoad() {

        super.viewDidLoad()



// Do any additional setup after loading the view.

    }



    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {

var cell = tableView.dequeueReusableCellWithIdentifier("CustomCell") as! CustomTableViewCell!

        if cell == nil

        {

            cell = CustomTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "CustomCell")

        }

        if let nome = object?["Nome"] as? String

        {

            cell.customNome.text = nome

        }

        if let categoria = object?["Categoria"] as? String

        {

            cell.customCategoria.text = categoria

        }

        let initialThumbnail = UIImage(named: "question")

        cell.customImage.image = initialThumbnail

        if let thumbnail = object?["imageFile"] as? PFFile

        {

            cell.customImage.file = thumbnail

            cell.customImage.loadInBackground()

        }

     return cell

    }





// In a storyboard-based application, you will often want to do a little preparation before navigation

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

// Get the new view controller using [segue destinationViewController].

//*let detailScene = segue.destinationViewController as! DetailViewController

let detailScene : DetailViewController = segue.destinationViewControlleras! DetailViewController

// Pass the selected object to the destination view controller.

iflet indexPath = self.tableView.indexPathForSelectedRow {

            let row = Int(indexPath.row)

            detailScene.currentObject = (objects?[row] as! PFObject)

        }

    }

    override func viewDidAppear(animated: Bool) {

// Refresh the table to ensure any data changes are displayed

        tableView.reloadData()

    }

}

錯誤:

2015-10-23 11:12:25.457 GuiaMogiNav[958:306603] -[UIImageView setFile:]: unrecognized selector sent to instance 0x176ce9a0

2015-10-23 11:12:25.459 GuiaMogiNav[958:306603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView setFile:]: unrecognized selector sent to instance 0x176ce9a0'

*** First throw call stack:

(0x243bd85b 0x35d32dff 0x243c3025 0x243c0c7f 0x242f01a8 0xf13fc 0xf1810 0x189017 0x28830d63 0x28830e89 0x28820df5 0x2883546f 0x285db5af 0x284edcc3 0x27db5b05 0x27db1201 0x27db1091 0x27db05b1 0x27db0263 0x27da9a1f 0x24380091 0x2437e387 0x2437e7c5 0x242d10d9 0x242d0ecd 0x2d646af9 0x2855a2dd 0xe435c 0x36480873)

libc++abi.dylib: terminating with uncaught exception of type NSException

(lldb) 

cell.customImage是PFImageView嗎?

UIImageView沒有屬性文件,但是PFImageView有屬性文件,您應該使用它來加載解析圖像。

並且,如果您使用的是Storyboard,則需要在身份檢查器中將customImage對象的類更改為PFImageView。

暫無
暫無

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

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