ios - 为什么仍然出现 "Could not cast value of type"错误?

标签 ios swift uitableview custom-controls

我试图在表格 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/

相关文章:

iOS JSON 解析返回 null

iphone - 隐藏 UITableviewcell 的 UIButton

ios - deselectRowAtIndexPath 和 cell setSelected 有什么区别?

ios - 如何从 MPMoviePlayerViewController 中删除 "Loading..."标签?

iOS 创建带有两个独立标签的按钮

ios - 类型 'X' 不符合协议(protocol) 'Encodable'

arrays - 如何简化 Swift 数组初始化

ios - tableviewcell 的附件 View 中的 UISwitch,通过选择器传递参数以使选择器函数看到 indexpath.row?

ios - Docusign 快速集成

ios - Swift:不知道如何调用我的委托(delegate)