gpt4 book ai didi

iOS Swift - 从选定的 TableView 单元格获取背景颜色

转载 作者:行者123 更新时间:2023-11-30 13:13:25 25 4
gpt4 key购买 nike

我有一个 ViewController,其中有一个 TableView。
通过代码,我填充 TableView 的单元格,并使用其他代码设置单元格的背景颜色。
注意 - 在代码的其他部分我用
执行此操作cell.backgroundColor = UIColorFromRGB(0xAA66CC)//尽管每个单元格的具体 RGB 值会有所不同。

现在在我的 Segue 到另一个 View 上,我不仅要检索“Name”元素,还要检索单元格的背景颜色并将其发送到下一个 ViewController。
我得到“名称”很好,但我不确定如何获取BackgroundColor值(然后我需要将其转换为字符串以进行传递)。

我的 Segue 代码是:

override func prepareForSegue(segue: UIStoryboardSeque, sender: AnyObject?)  
{
if segue.identifier = "GoToNextVC" {
if let cell = sender as? UITableViewCell {
let destination = segue.destinationViewController as! NextVC
let indx = tableView.IndexPathForCell(cell).row
destination.SelectedValue = self.peripherals[indx].name // This works fine.

destination.SelectedColor = **< I don't know what to do here >**
}
}
}

该代码可以获取 SelectedObject 名称,但我不确定如何获取单元格的背景颜色,以便我可以通过 Segue 传递它。

非常感谢您的帮助。

最佳答案

我会尝试:

cell.backgroundColor

如果你有细胞,那么你可以获得颜色。

override func prepareForSegue(segue: UIStoryboardSeque, sender: AnyObject?)  
{
if segue.identifier = "GoToNextVC" {
if let cell = sender as? UITableViewCell {
let destination = segue.destinationViewController as! NextVC
let indx = tableView.IndexPathForCell(cell).row
destination.SelectedValue = self.peripherals[indx].name // This works fine.

destination.SelectedColor = cell.backgroundColor
}
}
}

关于iOS Swift - 从选定的 TableView 单元格获取背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38489495/

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