2016-12-17 79 views
0

我一直在創建一個空閒的點擊遊戲/應用程序。您購買升級的方式是單擊表格單元格內的按鈕。我無法弄清楚的是,如何爲按鈕設置標題(我希望在每個按鈕上列出價格)。當我嘗試,我得到的錯誤,「類型的值‘(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'類(特別是網點)的聲明 –

回答

0

因失誤或不小心你試圖不設置標題按鈕動作到UIButton實例。這裏upgradePurchaseIBAction而不是IBOutlet

您需要將標題設置爲IBOutlet,因此如果未設置標題,請創建一個標題。

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

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

+0

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

+0

@AidenR。歡迎隊友:) –

相關問題