我试图在表格 View 上有一个自定义单元格,但收到无法转换类型值
错误。我已经查看了大多数其他帖子,但错误仍然发生。链接是错误的图片。 https://www.dropbox.com/s/kf1ukch3ciigr4z/Screenshot%202015-10-05%2023.15.11.png?dl=0
var arrayOfConcerts: [ConcertsController] = [ConcertsController]()
override func viewDidLoad() {
super.viewDidLoad()
self.setUpConcerts()
self.table1.dataSource = self
self.table1.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
}
func setUpConcerts(){
let concert1 = ConcertsController(imageName: "ACL.png")
arrayOfConcerts.append(concert1)
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arrayOfConcerts.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = table1.dequeueReusableCellWithIdentifier("cellconcert", forIndexPath: indexPath) as! CustomCellConcerts
let concert = arrayOfConcerts[indexPath.row]
cell!.setCell(concert.imageName)
return cell!
}
最佳答案
您需要使用自定义单元格类注册您的表格 View
YOUR_TABLE_VIEW.registerClass(UITableViewCell.self, forCellReuseIdentifier: CELL_IDENTIFIER)
在 did load 中添加这一行。如果您以编程方式添加 TableView ,请在分配委托(delegate)和数据源之后添加。 享受吧!!!
关于ios - 为什么仍然出现 "Could not cast value of type"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32961631/