类型'(UIButton) - >()'的值在tableView中没有成员'setTitle'

问题描述:

我一直在创建一个空闲的点击游戏/应用程序。您购买升级的方式是单击表格单元格内的按钮。我无法弄清楚的是,如何为按钮设置标题(我希望在每个按钮上列出价格)。当我尝试,我得到的错误,“类型的值‘(UIButton的) - >()’没有成员‘的setTitle’”我使用的Xcode 8.2,和斯威夫特3.类型'(UIButton) - >()'的值在tableView中没有成员'setTitle'

自定单元控制器:

@IBAction func upgradePurchase(_ sender: UIButton) { 
    if GlobalVariables.sharedManager.balance >= GlobalVariables.sharedManager.UpgradesPrice[GlobalVariables.sharedManager.UpgradesCurrent] { 

    } 
} 

的TableView控制器:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomTableViewCell 

    let row = indexPath.row 

    let showPrice = "Buy: $\(GlobalVariables.sharedManager.UpgradesPrice[row])" 

    cell.upgradeIdentifier.text = GlobalVariables.sharedManager.UpgradesName[row] 

    cell.upgradeDescription.text = GlobalVariables.sharedManager.UpgradesDesc[row] 

    cell.upgradePurchase.setTitle("\(showPrice)", for: .Normal) 

    GlobalVariables.sharedManager.UpgradesCurrent = GlobalVariables.sharedManager.UpgradesPrice[row] 

    return cell 
} 
+1

哪条线给出了该错误?并发布您的'CustomTableViewCell'类(特别是网点)的声明 –

因失误或不小心你试图不设置标题按钮动作到UIButton实例。这里upgradePurchaseIBAction而不是IBOutlet

您需要将标题设置为IBOutlet,因此如果未设置标题,请创建一个标题。

cell.btnupgradePurchase.setTitle("\(showPrice)", for: .normal) 

注:在斯威夫特三是.normal.Normal

+0

它的工作!我现在明白了! –

+0

@AidenR。欢迎队友:) –