質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

155閲覧

TableViewのClassエラーについて

ottotto

総合スコア22

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2018/11/02 05:18

前提・実現したいこと

現在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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

下の4つのfuncをviewDidLoad()の外に出して下さい。

投稿2018/11/02 05:31

fuzzball

総合スコア16731

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ottotto

2018/11/02 06:06

無事に解決することができました。 この度はありがとうございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問