私の問題はこれではない:私は別の配列に付加することができますfirebaseからすべてを読み込むことができます。しかし、私はそれを私のテーブルビューに表示することはできません。セクションを使用すると動作しませんが、私の配列の1つに静的な文字列を挿入すると、accidentMessages:String = ["Hu"]のように表示され、テーブルビューの "accident"セクションに表示されます。 それは、文字列(メッセージ)のでfirebaseからの私のメッセージを出力しますコンソール私の配列に追加されている必要があります。しかし何らかの理由で私はテーブルビューでそれを紹介することはできません。 ここfirebaseからフェッチされ、アレイに添加されるメッセージのコンソールログです。 enter image description hereテーブルビューには、私の追加の配列を示す、彼らが空でない場合でも、
メッセージ1、「ヘルプ」にする必要があり、メッセージ2が脅威である必要があり、メッセージ3は事故でなければなりません。しかし、それは表示されません、それが唯一のコンソールに表示さ
var helpMessage: [String] = []
var threatMessage: [String] = []
var accidentMessage: [String] = ["Hu"]
var sectionMessages: [Int: [String]] = [:]
let sectionTitle = ["Help:", "Threat:", "Accident"]
sectionMessages = [0: helpMessage, 1: threatMessage, 2: accidentMessage]
func numberOfSections(in tableView: UITableView) -> Int {
return sectionTitle.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return (sectionMessages[section]?.count)!
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let view = UIView()
view.backgroundColor = UIColor.orange
let image = UIImageView(image: sectionImages[section])
image.frame = CGRect(x: 5, y: 5, width: 35, height: 35)
view.addSubview(image)
let label = UILabel()
label.text = sectionTitle[section]
label.frame = CGRect(x: 45, y: 5, width: 100, height: 35)
view.addSubview(label)
return view
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 45
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
if cell == nil {
cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
}
cell!.textLabel?.text = sectionMessages[indexPath.section]![indexPath.row]
return cell!
}
のようなものを使用することができますhttps://github.com/Lukayne/Pushitt/blob/master/SkolprojektNr2/ViewController.swift – Lukayne
ありがとうございました!あなたは私のオブザーバーメソッドの1つに "sectionMessages = [0:helpMessage、1:threatMessage、2:accidentMessage]"を追加しなければなりませんでした。 – Lukayne