简体   繁体   中英

Overriding UITableView in Parse with Swift

All,

In swift while using Parse as my backend, I have created a class which inherits from PFQueryTableViewController. I see my data going into a tableview - thats fine.

I am trying to customise my cells a bit, and I overriding CellForRowAtIndexPath - like below :

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

   {
    var cellIdentifier = "eventCell"
    var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? PFTableViewCell
    if cell == nil {

        cell = PFTableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: cellIdentifier)

    }

    // configure cell
    var CellTitle = object.objectForKey("Title") as String
    cell?.textLabel = CellTitle
   }


}

As the object using comes back as [AnyObject] in swift, I have created a variable and I have casted it to a string. And then I am trying to show that string in Cell.textlabel.

I am getting the error : Cannot assign to the result of this expression. Can anyone please show me the right direction on this.

I think the problem is that you're attempting to assign a String directly to cell?.textLabel UILabel . Instead try changing this line:

cell?.textLabel = CellTitle

to this

cell.textLabel?.text = CellTitle

so you're setting the text property of the UILabel instead.

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