・Swift カスタムセルを再利用したtableViewの作り方 [初級向け]
https://qiita.com/pe-ta/items/116a2199b1f872ac6471
の記事通りに進めるとViewController.swiftのreturn cellの箇所で下記のエラーが出ます。
Cannot convert return expression of type 'CustomCellController' to return type 'UITableViewCell'
内容は
UITableViewCellを返さないといけないのにCustomControllerを返している
と。
コードの内容をちゃんと理解しきれていないレベルです。。
詳しい方いましたらよろしくお願いします。
ViewController
1 2 3import UIKit 4 5class ViewController: UIViewController , UITableViewDelegate , UITableViewDataSource { 6 7 @IBOutlet weak var myTable: UITableView! 8 9 override func viewDidLoad() { 10 myTable.register (UINib(nibName: "CunstomCellController", bundle: nil),forCellReuseIdentifier:"reusnableCell") 11 } 12 13 14 // セルの数を宣言 15 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 16 return 10 17 } 18 19 // セルの数を決める 20 func tableView(_ tableView: UITableView, cellForRowAt cells: IndexPath) -> UITableViewCell { 21 22 let Cell = tableView.dequeueReusableCell(withIdentifier: "reusnableCell", for: cells) as! CustomCellController 23 24 Cell.CellViewController (CountRows:cells) 25 return Cell // ←ここでエラーが出る 26 } 27} 28
CustomCellController
1import UIKit 2 3class CustomCellController: UIViewController { 4 5 @IBOutlet weak var tableImage: UIImageView! 6 7 @IBOutlet weak var tableLabel: UILabel! 8 9 func CellViewController(CountRows:IndexPath){ 10 11 self.tableLabel.text = String((CountRows.row)+1) 12 self.tableImage.image = UIImage(named: "meal.jpg") 13 } 14} 15 16
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。