0
我有一個具有動態子視圖的UITableView。當tableview改變時,單元格中的子視圖會丟失顏色
當表是靜態的,它看起來像這樣: 與T的全方位視角是自定義子視圖
但是,當我選擇編輯,然後拖動表格單元格中就失去它的顏色和T.
請告訴我這樣做的原因是什麼?
我初始化這樣的電池(這是一個原型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是這樣的:
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)
}
你能從視圖導航器中顯示tableView的視圖層次結構嗎? – Spectravideo328 2014-11-01 15:22:49
我認爲這只是拖動過程中單元格的正常行爲。你實際上並沒有失去「T」,但你看不到它,因爲它是白色的。如果您使用其他顏色,則會在拖動過程中看到它。一個正常的標籤(沒有任何修改的背景顏色)在拖動過程中也會丟失顏色。 – rdelmar 2014-11-01 16:11:14
@rdelmar你是對的。該標籤保持原狀。那麼它失去背景色的原因是什麼? – arnoapp 2014-11-01 18:21:45