[英]iOS Swift - Get BackgroundColor from selected TableView Cell
I have a ViewController with a TableView in it. 我有一个带有TableView的ViewController。
Via code, I populate the cells of the TableView and with other code, I set the Cell's BackgroundColor. 通过代码,我填充TableView的单元格,并使用其他代码设置单元格的BackgroundColor。
NOTE - in other parts of the code I do this with 注意-在代码的其他部分,我这样做
cell.backgroundColor = UIColorFromRGB(0xAA66CC) // although the specific RGB value for each cell will vary. cell.backgroundColor = UIColorFromRGB(0xAA66CC) //尽管每个单元格的特定RGB值会有所不同。
Now on my Segue to another View I want to retrieve, not only the "Name" element, but also the Cell's BackgroundColor and send it on to the next ViewController. 现在,在我的Segue上,我不仅要检索“名称”元素,还要检索单元格的BackgroundColor,然后将其发送到下一个ViewController。
I am getting the "Name" just fine, but I am not sure how to get the BackgroundColor value (which I will then need to convert to a String for passing). 我得到的“名称”很好,但是我不确定如何获取BackgroundColor值(然后我将需要将其转换为String进行传递)。
My Segue code is: 我的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 >**
}
}
}
That code works to get the SelectedObject Name, but I am not sure how to get the Cell's BackgroundColor so that I can then pass it through the Segue. 该代码可以获取SelectedObject名称,但是我不确定如何获取Cell的BackgroundColor,以便随后将其传递给Segue。
Your assistance would be greatly appreciated. 您的协助将不胜感激。
I will try with: 我将尝试:
cell.backgroundColor
If you have cell then you can get the color. 如果您有单元格,则可以获取颜色。
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
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.