tableViewに3つのセクションを作成したいのですが、このコードを実行すると、1つのセクションしか取得できず、それはitemsInSectionsです。誰かが私のテーブルビューにすべてのセクションとアイテムを表示するのを手伝ってもらえますか?
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"]
override func viewDidLoad() {
super.viewDidLoad()
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]
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! UITableViewCell
let text = self.itemsInSections[indexPath.section][indexPath.row]
cell.textLabel!.text = text
return cell
}
適切なメソッドシグネチャを使用する必要があります。
この:
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return self.sections.count
}
する必要があります:
func numberOfSections(in tableView: UITableView) -> Int {
return self.sections.count
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加