class customCell : UITableViewCell{
@IBOutlet weak var EventImage: UIImageView!
@IBOutlet weak var type: UILabel!
@IBOutlet weak var rating: UIImageView!
@IBOutlet weak var date: UILabel!
@IBOutlet weak var name: UILabel!
}
class EventHistoryViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var TableView: UITableView!
let k = ["hi","hey","yo","hello"]
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return k.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.TableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! customCell
cell.name!.text = self.k[index.row]
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
self.TableView.register(customCell.self, forCellReuseIdentifier: "cell")
TableView.delegate = self
TableView.dataSource = self
}
我做错了什么?这种情况下的程序在到达cell.name!.text = self.k [index.row] 时崩溃
答案 0 :(得分:0)
取代cell.name!.text
写cell.name.text
不要注册单元格
答案 1 :(得分:0)
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: VC_FavouriteCell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath as IndexPath) as! VC_FavouriteCell
cell.name.text = k[index.row]
return cell
}