簡體   English   中英

如何在TableView中更改按鈕的標題(快速)

[英]How to change the title of a Button in a TableView (Swift)

我試圖按一個按鈕來撥打電話號碼。 在TableView中,應該使用我添加的聯系人字典來更改按鈕的標題

這是按鈕:

    @IBAction func phoneLabel(sender: UIButton) {

    let url:NSURL = NSURL(string: "tel://contacts.phone")!
    UIApplication.shared.openURL(url as URL)
}

這是tableview,我正在嘗試將按鈕磁貼設置為聯系人電話號碼

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "ContactCell", for: indexPath) as! customCell
        let contact = contacts.contactWithIndex((indexPath as NSIndexPath).row)
        print(contact)
    cell.phoneLabel.setTitle("\(phone)", for:UIControlState)
   return cell
}

說按鈕沒有setTitle值時發生錯誤。 任何幫助都是極好的!

假設它是按鈕而不是標簽(查看發送者定義),則必須指定UIControlState.normal,而不是UIControlState。

https://developer.apple.com/reference/uikit/uicontrolstate/1618233-normal

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM