2016-07-20 4 views
0

ViewController와 TableView가 있습니다.
코드를 통해 TableView의 셀을 채우고 다른 코드로 셀의 BackgroundColor를 설정합니다.
참고 - 각 셀의 특정 RGB 값은 다양하지만 코드의 다른 부분에서는
cell.backgroundColor = UIColorFromRGB (0xAA66CC)으로 변경합니다.iOS Swift - 선택한 TableView 셀에서 BackgroundColor 가져 오기

내 Segue에서 다른 뷰를 검색하려면 "Name"요소뿐만 아니라 Cell의 BackgroundColor도 검색하여 다음 ViewController로 보내야합니다.
"Name"이 정상적으로 처리되지만 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 이름을 얻기 위해 작동하지만 난 다음 SEGUE를 통해 전달할 수 있도록 셀의 backgroundColor로 활용하는 방법을 모르겠습니다.

귀하의 협조에 큰 도움이 될 것입니다. 당신이 셀이있는 경우

cell.backgroundColor 

다음 색상을 얻을 수 있습니다 :

+0

나는 그것을 시도했지만 분명히 잘못된 것이있다. 'cell.backgroundColor'? –

+0

try cell.contentView.backgroundColor –

답변

0

내가 함께 할 것입니다.

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 
    } 
    } 
} 
+0

답장을 보내 주셔서 감사합니다. 내가 발견 한 것 : 1) ** cell.backgroundColor! **는 UIColor를 제공합니다 2) 그리고 ** cell.contentView.backgroundColor! ** 역시 UIColor를 제공합니다 - 차이점은 무엇인지 모르겠지만 시작. – Dhugalmac

+0

나는 UIColor를 RGBA로 변환하는 루틴을 가지고 있지만 이제 RGBA 값을 단일 HEX String으로 통합해야합니다. 어떤 제안? – Dhugalmac

관련 문제