简体   繁体   English

用Swift重写UITableView

[英]Overriding UITableView in Parse with Swift

All, 所有,

In swift while using Parse as my backend, I have created a class which inherits from PFQueryTableViewController. 在使用Parse作为后端的过程中,我迅速创建了一个从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 : 我试图稍微自定义单元格,然后覆盖CellForRowAtIndexPath-如下所示:

  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. 随着使用的对象迅速以[AnyObject]的形式返回,我创建了一个变量并将其转换为字符串。 And then I am trying to show that string in Cell.textlabel. 然后,我尝试在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 . 我认为问题是您正尝试直接将String分配给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. 因此,您改为设置UILabel的text属性。

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

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