【发布时间】:2015-08-03 14:13:14
【问题描述】:
我已经做了一个ViewController,在那个ViewController,我已经做了一个TableView,在TableView我已经添加了一个TableViewCell。
在TableViewCell 中,我添加了一个文本标签和一个图像。
我制作了一个名为customCell 的可可触摸文件并将其与TableView Cell 连接起来。
在ViewController 文件中我写了这个:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:customCell = tableView.dequeueReusableCellWithIdentifier("cell") as! customCell
cell.imageCountry.image = UIImage(named: "2xd.png")
cell.nameCountry.text = "hey"
return cell
这是我在 customCell 文件中写的: 导入 UIKit
class customCell: UITableViewCell {
@IBOutlet var imageCountry: UIImageView!
@IBOutlet var nameCountry: UILabel!
}
我已将 TableView 和 ViewController 与 DataSource 和 Delegate 连接起来。 当我运行我的代码时,这是我得到的错误:
Could not cast value of type 'UITableViewCell' (0x10d1119f0) to 'refreshing.customCell' (0x10b2f6dd0).
*refreshing 是项目的名称。
而臭虫的绿线设置为这一行:
let cell:customCell = tableView.dequeueReusableCellWithIdentifier("cell") as! customCell
有什么建议吗?
【问题讨论】:
-
@Rambo 在链接中尝试了两个答案,我在 AppDelegate.swift 文件的这一行中得到另一个错误:class AppDelegate: UIResponder, UIApplicationDelegate
-
听起来与“单元格”标识符关联的单元格未定义为
customCell。当您说“将其与 TableView Cell 连接”时,您实际上是如何做到的? -
@PhillipMills 在 MainStoryboard>ViewController>Table View>Cell>Identifier:"cell"
-
您是否还在情节提要中将单元格的类设置为
customCell?
标签: ios swift uitableview