2017-08-29 61 views
0

我想更新表視圖上的單元格,但單元格沒有讀取我傳遞並返回零的文本。tableview不讀標籤

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let myCell = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath) as! MyCell 
    let item = self.items[indexPath.row] 
    myCell.nameLabel?.text = item as? String 
    print(self.items[indexPath.row]) 
    myCell.myTableViewController = self 
    return myCell 
} 

class MyCell: UITableViewCell { 
    var myTableViewController: ChangeFeedViewController! 

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) { 
     super.init(style: style, reuseIdentifier: reuseIdentifier) 
    } 

    required init?(coder aDecoder: NSCoder) { 
     fatalError("init(coder:) has not been implemented") 
    } 

    @IBOutlet weak var nameLabel: UILabel! = { 
     let label = UILabel() 
     label.text = "Any Label" 
     return label 
    }() 

    @IBOutlet weak var actionButton: UIButton! = { 
     let button = UIButton() 
     button.setTitle("Action", for: .normal) 
     return button 
    }() 

    @IBAction func buttonHandleAction(_ sender: Any) { 
     handelAction() 
    } 

    func handelAction(){ 
     myTableViewController.deleteCell(cell: self) 
    } 
} 

回答

1

您需要修改outlet這樣並連接到您的MyCell class界面生成器。

@IBOutlet weak var nameLabel: UILabel! 
@IBOutlet weak var actionButton: UIButton!