Xcode 6.3 Parse SDK 1.7.1 PFTableViewCell Error “has incompatible type”

心已入冬 提交于 2020-01-02 04:16:08

问题


My code:

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")
    }

    // Extract values from the PFObject to display in the table cell
    if let username = object["username"] as? String {
        cell.customUser.text = username
    }
    if let title = object["Title"] as? String {
        cell.customTitle.text = title
    }

    // Display image
    var initialThumbnail = UIImage(named: "Swarm_Bee.png")

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

        thumbnail.getDataInBackgroundWithBlock{
            (imageData, error) -> Void in
            if error == nil {
                let image = UIImage(data: imageData!)
                cell.customImage.image = image
            }}
    }

    return cell

}

receives the following error

 overriding method with selector 'tableView:cellForRowAtIndexPath:object:' has incompatible type '(UITableView,NSIndexPath,PFObject) -> PFTableViewCell'

I have looked up all the compatibility errors (removing !). Another post had a similar issue:

Parse SDK 1.7.1 not working in Xcode 6.3

But only their number 3 error. All other issues in that post were addressed, but this error remains. Any solutions or recommendations of where to look?


回答1:


I figured it out. Use the following override function:

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

The difference is making the PFObject and the PFTableViewCell optionals.



来源:https://stackoverflow.com/questions/29992545/xcode-6-3-parse-sdk-1-7-1-pftableviewcell-error-has-incompatible-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!