С кодом ниже, я хочу напечатать имя и цену в каждой ячейке таблицы.Сборка выполняется без проблем, но когда я запускаю приложение, в var item1 = arrData[i]["name"]
появляется сообщение об ошибке Bad Instruction
. Вот полный код:
class ViewController3: UIViewController, UITableViewDelegate,
UITableViewDataSource {
let arrData: [[String:Any]] = [
["name": "spiderman", "price": 5000],
["name": "superman", "price": 15000],
["name": "batman", "price": 3000],
["name": "wonder woman", "price": 25000],
["name": "gundala", "price": 15000],
]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arrData.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let identifier = "Cell"
var cell = tableView.dequeueReusableCell(withIdentifier: identifier)
var i = 0
while i <= arrData.count {
var item1 = arrData[i]["name"]
var item2 = arrData[i]["price"]
cell?.textLabel?.text = "\(item1) \(item2)"
i = i + 1
}
return cell!
}
}