2014-11-01 4 views
0

동적 하위 뷰가있는 UITableView가 있습니다. 테이블 뷰가 변경 될 때 셀의 하위 뷰가 색을 잃습니다.

테이블은 다음과 같습니다 정적

: enter image description here T와 라운드보기는 사용자 정의 서브 뷰

입니다하지만 편집을 선택하고 드래그 할 때 테이블이 색상과 T.의 IT가 풀리면 셀

enter image description here

무슨 이유?

는이 같은 셀을 초기화 (그것은 프로토 타입 IB 셀의) :

func configureCell(cell: UITableViewCell, atIndexPath indexPath: NSIndexPath) { 
     let object = self.fetchedResultsController.objectAtIndexPath(indexPath) as Item 
     //cell.textLabel.text = object.valueForKey("name")!.description 
     let cSubView = cell.viewWithTag(100) as RoundedIcon 
     cSubView.setUpViewWithFirstLetter(String(first(object.name)!).uppercaseString) 
    } 

그리고 RoundedIcon는 다음과 같이 작동합니다 rdelmar의 코멘트는 그 올바른 방향으로 절 지적

override init(frame: CGRect) { 
    super.init(frame: frame) 
    self.layer.cornerRadius = self.frame.size.width/2; 
    self.layer.borderWidth = 1.0; 
    self.layer.borderColor = UIColor.lightGrayColor().CGColor; 
    self.clipsToBounds = true; 
} 

func setUpViewWithFirstLetter(letter:String){ 
     self.backgroundColor = RoundedIcon.UIColorFromRGB(0x68C3A3) 
     let theLetterLabel = UILabel() 
     theLetterLabel.text = letter 
     theLetterLabel.textColor = UIColor.whiteColor() 
     theLetterLabel.textAlignment = .Center 
     theLetterLabel.font = UIFont.systemFontOfSize(25) 
     self.addSubview(theLetterLabel) 
     theLetterLabel.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: self.frame.size) 
    } 
+0

뷰 탐색기에서 tableView의 뷰 계층 구조를 표시 할 수 있습니까? – Spectravideo328

+1

이것은 드래그하는 동안 셀의 정상적인 동작이라고 생각합니다. 당신은 실제로 "T"를 잃지 않고, 흰색이기 때문에 그것을 볼 수 없습니다. 다른 색상으로 만들면 드래그하는 동안 볼 수 있습니다. 배경색이있는 일반 레이블 (수정하지 않은 레이블)은 끌기 도중 색상이 손실됩니다. – rdelmar

+0

@rdelmar 당신이 옳습니다. 라벨은 제 위치에 있습니다. 배경색을 잃어버린 이유는 무엇입니까? – arnoapp

답변

1

@ UITableview는 모든 셀의 배경색을 다음과 같이 변경합니다.

UIColor(white:0,alpha:0) 

보기가 그것의 색깔을 바꿀 필요가 있습니다. 다음과 같이 신속하게 작동하는 backgroundColor 속성 설정자를 변경해야합니다.

//override this setter to avoid color resetting on drag 
override var backgroundColor:UIColor?{ 
    didSet { 
     //check the color after setting - you also can do it earlier 
     if let bgCol = backgroundColor{ 
      println(bgCol) 
      if bgCol == UIColor(white: 0, alpha: 0){ //check if it's settled by the table 
       super.backgroundColor = yourColor //set it back to your color 
      } 
     } 
    } 
} 
관련 문제