2016-06-21 54 views
1

選擇單元格時隱藏圓形視圖。如何解決它?帶着SubviewToFront不起作用。選中單元格時隱藏圓形視圖

screenshot

override func setSelected(selected: Bool, animated: Bool) { 
    super.setSelected(selected, animated: animated) 
    self.selectedBackgroundView?.bringSubviewToFront(statusView) 
} 

請幫幫忙!

+0

'select cell - > attribute inspector - > selction' set to none and check ... is it working or not ??? ??? –

+0

http://stackoverflow.com/questions/6745919/uitableviewcell-subview-disappears-when-cell-is-selected此鏈接可能對您有用 – kamwysoc

+0

嘗試將圖片視圖,而不是uiview –

回答

0

設置您的視圖的backgroundColor通過覆蓋func setHighlighted(highlighted: Bool, animated: Bool)func setSelected(selected: Bool, animated: Bool)這樣的:

class Cell: UITableViewCell { 
var redView :UIView! 
var yellowView :UIView! 

override init(style: UITableViewCellStyle, reuseIdentifier: String?) { 
    super.init(style: style, reuseIdentifier: reuseIdentifier) 

    redView = UIView() 
    redView.frame = CGRect(x: 0, y: 10, width: 100, height: 20) 
    self.contentView.addSubview(redView) 

    yellowView = UIView() 
    yellowView.frame = CGRect(x: 200, y: 10, width: 100, height: 20) 
    self.contentView.addSubview(yellowView) 

    redView.backgroundColor = UIColor.redColor() 
    yellowView.backgroundColor = UIColor.yellowColor() 
} 

required init?(coder aDecoder: NSCoder) { 
    fatalError("init(coder:) has not been implemented") 
} 

override func setSelected(selected: Bool, animated: Bool) { 
    super.setSelected(selected, animated: animated) 
    redView.backgroundColor = UIColor.redColor() 
    yellowView.backgroundColor = UIColor.yellowColor() 
} 
override func setHighlighted(highlighted: Bool, animated: Bool) { 
    super.setHighlighted(highlighted, animated: animated) 
    redView.backgroundColor = UIColor.redColor() 
    yellowView.backgroundColor = UIColor.yellowColor() 
} 
} 
+0

是的,這就是我想要做的。謝謝。 –

0

在選擇細胞的UIView,所有塗在單元格的背景,所以UIView的是隱藏的。如果選擇後重新繪製,那麼一切都會。

override func setSelected(selected: Bool, animated: Bool) { 
    super.setSelected(selected, animated: animated) 

    if selected { 
     switch status { 
     case "8","9": 
      // print("Cancel") 
      statusView.backgroundColor = FlatUIColors.thunderBirdColor() 
     case "10","11","12": 
      // print("Success") 
      statusView.backgroundColor = FlatUIColors.nephritisColor() 
     case "20","21","22","23": 
      // print("Wait") 
      statusView.backgroundColor = FlatUIColors.wetAsphaltColor() 
     case "30","31": 
      // print("Processing") 
      statusView.backgroundColor = FlatUIColors.peterRiverColor() 
     default: 
      break 
     } 
    } 
} 
相關問題