0
私は2つのラベルとボタンを持つカスタムUITableViewCellを持っています。セルは、それ自身のクラスがあります。テーブルビューを含むビューコントローラ内部Table Cellから情報を取得しますか?
class personTableCell: UITableViewCell {
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var emailLabel: UILabel!
@IBAction func inviteButtonPressed(_ sender: Any) {
self.accessoryType = .checkmark
}
}
を、私はこの方法で表にセルを追加:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "person", for: indexPath) as? personTableCell
cell?.nameLabel.text = results[indexPath.row].name
cell?.emailLabel.text = results[indexPath.row].email
return cell!
}
は、ユーザーが内部のボタンを押すとセルを@IBAction func inviteButtonPressed
と呼びます。セルのラベルのテキストを、テーブルと同じビューコントローラで初期化された配列に追加します。
@IBAction func inviteButtonPressed
がテーブルのビューコントローラとして別のファイルにある場合、どうすればこのようなことができますか?
ない関連TableViewCellクラスで:鳥のためにあまりにも多くの質問と感嘆符。真剣に:決してテーブルビューのセル(ビュー)から情報を取得し、データソース配列(モデル)から取得してください – vadian
@vadianはしっかりしてください? – MarksCode
'dequeueReusableCell(withIdentifier:indexPath)'は非オプションのセルを返します。それはオプションのダウンキャストにはかなり馬鹿です。セルは明らかにInterface Builderで作成されているため、存在していることがわかります。 – vadian