前提・実現したいこと
エラーを解決したいです
発生している問題・エラーメッセージ
Cannot convert return expression of type 'UITableViewCell.Type' to return type 'UITableViewCell'
該当のソースコード
swift
1class TableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 2 @IBOutlet weak var tableView: UITableView! 3 4 override func viewDidLoad() { 5 super.viewDidLoad() 6 // Do any additional setup after loading the view, typically from a nib. 7 } 8 9 override func didReceiveMemoryWarning() { 10 super.didReceiveMemoryWarning() 11 // Dispose of any resources that can be recreated. 12 } 13 14 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 15 return 100 16 } 17 18 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{ 19 return 20 20 } 21 22 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{ 23 if indexPath.section == 0 { 24 let cell = tableView.dequeueReusableCell(withIdentifier: "Table") as! TableViewCell 25 cell.item.text = "(indexPath.row)" 26 return cell 27 } 28 29 return UITableViewCell 30 31 }
class TableViewCell: UITableViewCell { @IBOutlet weak var item: UILabel! override func awakeFromNib() { super.awakeFromNib() // Initialization code } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) // Configure the view for the selected state } }
何を調べていいかもわからない状態でどなたか助けていただきたいです、、、
個人的にはエラーでUITableViewCell.Typeの.Typeとなっているのに違和感を覚えるのですが何か関係はあるのでしょうか?
if indexPath.section == 0 { となっていますが、セクション番号0以外のときのセルはどうするつもりなのでしょうか?
return UITableViewCellおそらくですがここの部分がそれに当たるのではないかと思います。参考書をみてアプリを作成しているのでところどころ私自身理解があまく、申し訳ございません。
あなたはどうしたいと思っているのか?という質問なのですが、if indexPath.section == 0 { というコードも理解できていない(特に意味はない)ということでしょうか?
そうです。if indexPath.section == 0のコードの意味があるかわからなかったのですが参考書のままに書いてしまいました。隊への手数鵜をおかっけしました。
回答1件
あなたの回答
tips
プレビュー