我正在尝试在我的项目中使用名为 SwipeCellKit
的 pod,该 pod 添加了一个名为 SwipeTableViewCell 的类。到目前为止我所做的是:
- 为 Storyboard创建一个 View Controller 。
- 创建一个
UIViewController
类。 - 将
SwipeCellKit
导入到 Swift 文件中。 - 将 View Controller 分配给类。
- 将 TableView 添加到 View Controller 。
- 将委托(delegate)和数据源从 TableView 连接到 View Controller 。
- 将原型(prototype)单元格添加到 TableView ,并将其命名为“单元格”以作为其可重用标识符。
- 将单元格类更改为 SwipeTableViewCell。
- 将 TableView 委托(delegate)添加到 View Controller 。
- 将
numberOfRows
和cellForRow
函数添加到我的 UIViewController 类。
这是 cellForRow
的实现:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! SwipeTableViewCell;
return cell;
}
但是我在 let cell = ...
上出错,说:
Could not cast value of type 'UITableViewCell' to 'SwipeCellKit.SwipeTableViewCell'
为什么?以及如何解决这个问题?我想我已经安排好了一切。我错过了什么吗?
最佳答案
是什么为我解决了这个问题:
在Main.Storyboard(或者你有你的观点的地方),确保你想在任何地方使用可重用的“单元格”,在右 Pane 的身份检查器中,你有以下内容:
- 类设置为SwipeTableViewCell
- 模块设置为 SwipeCellKit。
关于ios - 无法将类型 'UITableViewCell' 的值转换为 'SwipeCellKit.SwipeTableViewCell',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54399985/