Я пытаюсь отобразить два массива в двух разных ячейках в виде таблицы, но это не работает, может ли кто-нибудь помочь мне решить эту проблему, я используя Xcode8 и Swift3, и это мой код TableView.Как отобразить два массива в двух разных ячейках в UITableView с помощью swift3
это, как я хочу, чтобы отобразить два массива:
Row1 = ааа
row2 = 11111
row3 = БББ
row4 = 2222
row5 = КЦИК
ряд6 = 3333
row7 = ддд
row8 = еее
row9 = FFF
Мой код:
import UIKit
class _CellsTableViewController: UITableViewController {
var array1 = [String]()
var array2 = [String]()
override func viewDidLoad() {
super.viewDidLoad()
array1 = ["aaa","bbb","ccc","ddd","eee","fff"]
array2 = ["11111","22222","33333"]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return array1.count + array2.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = array1[indexPath.row]
return cell
}
else {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath)
cell.textLabel?.text = array2[indexPath.row]
return cell
}
}
}
, что проблема у столкнулась –
Фатальная ошибка: индекс вне диапазона, то будет ошибка. –
Почему, черт возьми, вы думаете, 'если indexPath.row == 0' сделал бы это? Кажется основной проблемой программирования. –