在cellForRowAtIndexPath中将UIButton视为UILabel

时间:2015-12-06 17:52:13

标签: ios swift uitableview parse-platform uibutton

如何在cellForRowAtIndexPath中将UIButton视为UILabel,我想在cellForRowAtIndexPath中将其称为UILabel。

我收到此错误:

  

无法将String类型的值赋值为UIButton

使用PFQueryTableViewController。

 cell.cityButton = object?.objectForKey("City") as? String

cell.locationLabel.text = object?.objectForKey("eventLocation") as? String

2 个答案:

答案 0 :(得分:2)

您正在尝试将cityButton设置为等于(可选)String,这显然不起作用。相反,您希望将按钮的标题设置为该字符串。试试这个:

cell.cityButton.setTitle(object?.objectForKey("City") as? String forState: .Normal)

答案 1 :(得分:2)

试试这个:cell.cityButton.setTitle(object?.objectForKey("City") as? String forState: .Normal)