更新到 iOS9 后,我开始在以下代码中看到一个奇怪的警告:
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
{
var result: UIView?
if UserPerspective.List == currentUser.perspective.value
{
result = tableView.dequeueReusableCellWithIdentifier("CustomHeader") as? UIView
}
return result
}
正如标题中所述,我收到以下警告:
Cast from "UITableViewCell" to unrelated type "UIView" always fails
我不明白为什么它失败,因为 UITableViewCell 是 UIView 的子类,那么强制转换应该没问题。然而 swift 编译器并不这么认为:)
最佳答案
你不应该转换它。
这应该足够了
let result = tableView.dequeueReusableCellWithIdentifier("CustomHeader")
结果是UITableViewCell?
如果您有自定义 UITableViewCell,我们将其称为 customTableViewCell
,您可以执行以下操作:
let result = tableView.dequeueReusableCellWithIdentifier("CustomHeader") as! customTableViewCell
关于ios - 从 "UITableViewCell"转换为不相关类型 "UIView"总是失败 iOS9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32966010/