前提・実現したいこと
現在TableViewを利用した簡単なセルの作成を勉強しております。
class TimelineViewController: UIViewController, UITableViewDelegate, UITableViewDataSource を宣言した際にエラーコードが出現し、検索を行いましたが解決に至りませんでしたので質問させていただきます。
ご教授いただけましたら幸いです。
お手数ですが、何卒宜しくお願いします。
発生している問題・エラーメッセージ
Type 'TimelineViewController' does not conform to protocol 'UITableViewDataSource'
該当のソースコード
import UIKit let sectionTitle = ["category1", "category2", "category3" ] let tweetData0 = [("test1","test2"), ("test3","test4")] let tweetData1 = [("test5","test6"), ("test7","test8")] let tweetData2 = [("test9","test10"), ("test11","test12")] let tableData = [tweetData0, tweetData1, tweetData2] class TimelineViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { override func viewDidLoad() { super.viewDidLoad() let timelineTableView = UITableView(frame: view.frame, style: .plain) timelineTableView.delegate = self timelineTableView.dataSource = self view.addSubview(timelineTableView) func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { let tweetData = tableData[section] return tweetData.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cell") let tweetData = tableData[(indexPath as NSIndexPath).section] let cellData = tweetData[(indexPath as NSIndexPath).row] cell.textLabel?.text = cellData.0 cell.detailTextLabel?.text = cellData.1 return cell } func numberOfSections(in tableView: UITableView) -> Int { return sectionTitle.count } func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return sectionTitle[section] } } }
試したこと
必須メソッドの記載漏れかと思い、下記のサイトを試しましたがエラーコードに変化は認められませんでした。
http://westhillworker.com/swift-error-not-protocol/
補足情報(FW/ツールのバージョンなど)
xcode9.2
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/02 06:06