gpt4 book ai didi

ios - 从 "UITableViewCell"转换为无关类型 "UIView"总是失败 iOS9

转载 作者:可可西里 更新时间:2023-11-01 00:52:22 24 4
gpt4 key购买 nike

更新到 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com