私はテーブルビューを表示したいが、各アイテムの "ステータス"によってセクションごとに区切っているという問題があります。私は、単純な文字列配列でそれを行う方法を知っているが、私はクラス(Aluno)配列で、この作業をするために得ることができない、ここに私のコードは、これまでのところです:UITableViewがすべてのセクションを表示していません
import UIKit
class DeliveriesTVC: UITableViewController {
let sections = ["Delivered", "Not Delivered"]
var studentList: [Array<Student>] = [[], []]
override func viewDidLoad() {
super.viewDidLoad()
for i in 0...5{
studentList[0].append(Student(alunoNome: "Aluno \(i)", alunoImg: "dani_test", alunoStatus: "Delivered"))
}
for i in 6...10{
studentList[1].append(Student(alunoNome: "Aluno \(i)", alunoImg: "dani_test", alunoStatus: "Not Delivered"))
}
self.title = "Deliveries"
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let cellEntrega = tableView.dequeueReusableCell(withIdentifier: "EntregaCell", for: indexPath) as? EntregaCell {
let entregaCell = studentList[indexPath.section][indexPath.row]
// here i call a function in my TableViewCell class that update the cell itself
cellEntrega.updateAlunoUI(Aluno: entregaCell)
return cellEntrega
} else {
return UITableViewCell()
}
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return listaAlunos[section].count
}
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return self.sections[section]
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
}
出力では、私はちょうど取得します「第1セクション」は名前を付けずに、各セクションの名前とセクションの数を設定しても表示されます。私はどこにでも見ましたが、私は解決策を見つけることができませんでした。あなたのnumberOfSectionInTableView
機能については
実際には、データソースを把握する必要があります。あなたの 'cellForRowAt'は' studentList'という名前の配列の配列に基づいています。あなたの 'numberOfRowsInSection'は' listaAlunos'という名前の配列に基づいています(おそらく翻訳の見落とし)。 'titleForHeaderInSection'は' sections'という別の配列に基づいています。そして、 'numberOfSections'を' 2'の値で不必要にハードコードします。その数字を厳しくしないでください。 – rmaddy
ええ、それは翻訳問題です、彼らは実際には同じ、申し訳ありません!私は文字通りすべてを試したのでセクションの数をハードコーディングしました。そして最終的に私の問題は間違っていて分かりませんでした。助けてくれてありがとう! –