gpt4 book ai didi

ios - willDisplayCell 委托(delegate)方法 Swift

转载 作者:搜寻专家 更新时间:2023-10-30 22:34:42 25 4
gpt4 key购买 nike

我一直在围绕 tableview 工作,但遇到了以下问题。

据我所知,willDisplayCell 委托(delegate)方法应该允许我访问当前的单元格设计。
我的问题是 - 我无法访问的实例自定义单元格,因为它是在 cellForRowAtIndexPath 方法中单独声明的。如果我再次声明它 - 我无法访问它的对象(我在那里有一个 uibutton)。或者我可能误解了这种方法的使用。

这是我的代码

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

//declaring the cell variable again

var cell:TblCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! TblCell

if let text = cell.lblCarName.text where !text.isEmpty {
cell.act1.hidden = false
} else {
println("Failed")
}
}

我在代码中看到的目标是访问 TblCell uilabel 并对其应用条件 - 如果它为 nil - 显示 uibutton

注意:我的委托(delegate)和数据源设置正确,方法正在运行,应用程序编译,但条件没有按我的预期工作。

谢谢!

最佳答案

此委托(delegate)为您提供现在将要显示的单元格实例,并且该特定单元格实际上作为 cell 参数发送。对其进行类型转换并使用条件。

试试这个代码。

var cell:TblCell = cell as! TblCell

if let text = cell.lblCarName.text where !text.isEmpty {
cell.act1.hidden = false
} else {
println("Failed")
}

关于ios - willDisplayCell 委托(delegate)方法 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32306863/

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