import UIKit class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet var table: UITableView! @IBOutlet var label: UILabel! var models: [(title: String, note: String)] = [] override func viewDidLoad() { super.viewDidLoad() table.delegate = self table.dataSource = self title = "Notes" } @IBAction func didTapNewNote() { } func numberOfSections(in tableView: UITableView) -> Int { return models.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) cell.textLabel?.text = models[indexPath.row].title cell.detailTextLabel?.text = models[indexPath.row].note return cell } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: true) guard let vc = storyboard?.instantiateViewController(identifier: "note") as? NoteViewController else { return } vc.title = "Note" navigationController?.pushViewController(vc,animated: true) } }
Xcode初心者です。
二行目のclass ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {にType 'ViewController' does not conform to protocol 'UITableViewDataSource'Do you want to add protocol stubs?というエラーが出ます。
解決方法を教えて欲しいです。
func numberOfSections(in tableView: UITableView) じゃなくて、func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) を実装すべきでは。
あなたの回答
tips
プレビュー