我有一个带有TableView的ViewController
通过代码,我填充TableView的单元格和其他代码,我设置了Cell的BackgroundColor。
注意 - 在代码的其他部分,我用这个做
cell.backgroundColor = UIColorFromRGB(0xAA66CC) //虽然每个单元格的特定RGB值会有所不同。
现在,我想要查看另一个视图,而不仅仅是"名称"元素,也是Cell的BackgroundColor,并将其发送到下一个ViewController 我正在获得"姓名"很好,但我不知道如何获取BackgroundColor值(我将需要转换为String传递)。
我的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名称,但我不知道如何获取Cell的BackgroundColor,以便我可以通过Segue传递它。
非常感谢您的协助。
答案 0 :(得分:0)
我会尝试:
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
}
}
}