我想對應我的字典中的「主要」到與每個主要相關的圖片,以便它顯示在單元格中。訪問字符串鍵顯示獲取圖像(斯威夫特)
import Foundation
class ClassRosterModel {
var studentsRoster = [Dictionary<String, String>]()
init() {
studentsRoster.append(["name": "Kaz, Alex", "number" : "s0834347", "major" : "SE"])
studentsRoster.append(["name": "O'Rore, Ryan", "number" : "s0835357", "major" : "SE"])
studentsRoster.append(["name": "Lote, Lote", "number" : "s0835357", "major" : "SE"])
studentsRoster.append(["name": "Flora, Nico", "number" : "s0748324", "major" : "MA"])
}
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("studentCell", forIndexPath: indexPath)
// Configure the cell...
cell.textLabel?.text = studentsList[indexPath.row]["name"]
cell.detailTextLabel?.text = studentsList[indexPath.row]["number"]
print("Student's name: \(studentsList[indexPath.row]["name"])")
print("Student's number: \(studentsList[indexPath.row]["number"])")
return cell
目前還不清楚你的問題是什麼。請更新您的問題。 – rmaddy
那麼這有什麼問題? – Alexander
我不會使用字典數組,你應該只使用一個結構體。但無論如何,這應該工作,你已經添加「主要」 –