2016-06-21 52 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 
     } 
    } 
} 
相关问题