0
私はUITableView
私はちょうど3つの細胞を持つ必要があります。これは私がIBで持っているものです:。すべてのセルにUITextField
が含まれています。そのため、カスタムセルを使用しています。各セルは、対応するUITextField
を出口としてCustomCell
クラスにバインドされています。 UItexField
のテキストをテーブルのUIViewController
に渡すためのプロトコルもあります。 UIViewController
で固定数のカスタムセルでテーブルビューを正しく実装するにはどうすればよいですか?
私はこのている:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = UITableViewCell()
switch indexPath.row {
case 0:
cell = tableView.dequeueReusableCell(withIdentifier: "firstNameCell", for: indexPath)
(cell as! FirstNameTableViewCell).delegate = self
case 1:
cell = tableView.dequeueReusableCell(withIdentifier: "lastNameCell", for: indexPath)
(cell as! LastNameTableViewCell).delegate = self
case 2:
cell = tableView.dequeueReusableCell(withIdentifier: "birthdateCell", for: indexPath)
(cell as! BirthdateTableViewCell).delegate = self
default:
break
}
return cell
}
しかし、ここで:
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(FirstNameTableViewCell.self, forCellReuseIdentifier: "firstNameCell")
tableView.register(LastNameTableViewCell.self, forCellReuseIdentifier: "lastNameCell")
tableView.register(BirthdateTableViewCell.self, forCellReuseIdentifier: "birthdateCell")
}
セルの内容が示されていません。
このシナリオを扱う正しい方法はどれですか?
固定セルがある場合は、ストーリーボード自体でUITableViewControllerにスタティックセルを作成し、テキストフィールドからIBOutletをVCに直接描画することはできません。セルは再利用されないので、xCodeは不平を言わず、論理的な観点からも意味をなさない:)固定数のセルに対してデリゲートを作成する手間は不要です。 –
サイドノート、関連性がありません:** Interface Builderで設計されたセルを登録する必要はありません。 – vadian
@vadianあなたはストーリーボードを意味します、そうですか? –