[英]iOS swift 3 - custom table cell, but no data is showing on the tableview
[英]Swift 3: Custom TableView Cell not showing
嘿,所以我試圖創建一個自定義單元,並且已經正確鏈接了故事板中的所有內容,但是由於某種原因,當我運行時它不會顯示任何內容。 我嘗試對其進行測試,看來自定義單元對象甚至都沒有創建。
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]時崩潰
代替cell.name!.text
寫入cell.name.text
不要注冊單元
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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.