【发布时间】:2015-10-06 09:11:18
【问题描述】:
更新到 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
}
如标题中所述,我收到以下警告:
从“UITableViewCell”转换为不相关类型“UIView”总是失败
我不明白为什么它会失败,因为 UITableViewCell 是 UIView 的子类,那么演员应该没问题。然而 swift 编译器不这么认为:)
【问题讨论】:
-
我想没有必要将 UIView 子类转换为 UIView。
-
您要从 UITableViewCell 投射?到 UIView,那确实总是会失败。你可以投射到 UIView 吗? - 那么它总是会成功。所以最好的选择是根本不施放——一切都会如你所愿。