いつもお世話になっています。
Storyboard上でViewControllerにTableViewを貼り付け、
TableViewCellはカスタムセルとしてxibで生成しています。
TableViewCellのxibにさらにTableViewを貼り付け、そのセルの処理を以下のように記述しました。
swift
1import UIKit 2 3class CustomCell: UITableViewCell { 4 5 @IBOutlet weak var innerTableView: UITableView! { 6 didSet { 7 let nib = UINib(nibName: "InnerTableCell", bundle: nil) 8 innerTableView.register(nib, forCellReuseIdentifier: "innerTableCell") 9 } 10 } 11 12 var user = User([:]) 13 var userData = [[String: Any]]() 14 15 override func awakeFromNib() { 16 super.awakeFromNib() 17 18 innerTableView.dataSource = self 19 innerTableView.delegate = self 20 } 21 22 override func setSelected(_ selected: Bool, animated: Bool) { 23 super.setSelected(selected, animated: animated) 24 } 25 26 func apply(user: User) { 27 self.user = user 28 userData.append(["id": user.id ?? 0, "row": user.height ?? 0, "title": "身長", "value": user.bloodtype ?? "未選択"]) 29 ・・・ append続く 30 } 31} 32 33extension CustomCell: UITableViewDataSource { 34 35 func numberOfSectionsInTableView(tableView: UITableView) -> Int { 36 return 1; 37 } 38 39 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 40 return profile.count 41 } 42 43 // 呼ばれない 44 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 45 let cell = tableView.dequeueReusableCell(withIdentifier: "innerTableCell", for: indexPath) as! InnerTableCell 46 return cell 47 } 48 49} 50 51extension CustomCell: UITableViewDelegate { 52 53 // 試しに設定してみた 54 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 55 return 400.0 56 } 57 58}
この処理だと
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
が呼ばれず、何も表示されませんでした。
ちなみに呼び出し元のテーブルでは
swift
1func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 2 let cellType = CellType(rawValue: indexPath.row) 3 switch cellType! { 4 case .ProfileCell: 5 let cell = tableView.dequeueReusableCell(withIdentifier: "customCell", for: indexPath) as! CustomCell 6 cell.apply(user: user) 7 return cell 8 default: 9 let cell = tableView.dequeueReusableCell(withIdentifier: "blankCell", for: indexPath) as! BlankCell 10 return cell 11 } 12}
のように設定しています。
まだまだ理解力不足で何が原因なのかがわからず・・・
時間だけを費やしてしまっています。
TableViewのネスト方法も検索してみましたが、ほぼネタがなく有力な情報が得られない状態です。
どなたか解決できる方がいらっしゃいましたらご教授いただきたいです。
よろしくお願いいたします。
追加:
xibの状態も添付しました。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。