2017-08-29 6 views
0

テーブルビューのセルを更新しようとしていますが、セルがテキストを読み取っていないため、渡してnilを返しています。テーブルビューがラベルを読み取らない

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! 
関連する問題