我无法从解析中加载图像。大拇指称为“问题”没关系,但是当我尝试从解析加载图像时,会发生错误并且应用程序崩溃
看看:
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)
答案 0 :(得分:2)
是cell.customImage一个PFImageView?
UIImageView没有属性文件,但PFImageView有它,你应该用它来加载解析图像。
如果您使用的是Storyboard,则需要在身份检查器中将customImage对象的类更改为PFImageView。