以下のコードを作成しましたが、 'Section 1'ヘッダーと要素だけが表示されます。私はすべての3つのヘッダーの下に対応する要素が表示されることを期待します、なぜこれは起こっていないのですか?tableViewのセクションが表示されない
import Foundation
import UIKit
class summary: UIViewController, UITableViewDelegate, UITableViewDataSource {
var itemsInSections: Array<Array<String>> = [["1A", "1B", "1C"], ["2A", "2B"], ["3A", "3B", "3C", "3D", "3E"]]
var sections: Array<String> = ["Section 1", "Section 2", "Section 3"]
@IBOutlet var tableView: UITableView!
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:TableViewCell1 = self.tableView.dequeueReusableCell(withIdentifier: "cell") as! TableViewCell1
cell.label.text = "\(itemsInSections[indexPath.section][indexPath.row])"
return cell
}
override func viewDidLoad() {
let nib = UINib(nibName: "tblcell", bundle: nil)
tableView.register(nib, forCellReuseIdentifier: "cell")
self.tableView.dataSource = self
self.tableView.delegate = self
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return self.sections.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.itemsInSections[section].count
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return self.sections[section]
}
}
'numberOfSectionsInTableView(tableView:UITableView)'も呼び出されていますか?ドキュメントでは、署名は 'optional func numberOfSections(tableView:UITableView) - > Int'ですので、正しいものを実装していないので、デフォルトでは1セクションが返されていると思います。 – Larme
ちょっと@Larme、あなたは完全にそこにいます、それは呼ばれていませんでした。ご助力ありがとうございます :) – MattBlack