我有一個自定義UIView
,它在其drawRect
方法中繪製了幾行。然後,我創建一個常規的UITableViewCell
並將其添加到我的自定義UIView
。我的自定義UIView
中的圖形代碼僅在選擇表格視圖單元格時顯示。一旦它被取消,所有的行都消失了。UTableViewCell子視圖中的drawRect僅在選中單元格時起作用
我強制setNeedsDisplay
在運行時被多次調用來測試。不幸的是,這沒有什麼區別。單元格未選中時,線條不顯示。
任何想法?
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = createEmptyCell()
let selectionView = SelectionView(frame: cell.bounds)
childSelectionView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
cell.addSubview(childSelectionView)
return cell
}
這裏是一個空類
override func drawRect(rect: CGRect) {
super.drawRect(rect)
let path = UIBezierPath()
path.moveToPoint(CGPoint(x: 20,y: 50))
path.addLineToPoint(CGPoint(x: bounds.width/2 - 4, y: 50))
path.addLineToPoint(CGPoint(x: bounds.width/2, y: 58))
path.addLineToPoint(CGPoint(x: bounds.width/2 + 4, y: 50))
path.addLineToPoint(CGPoint(x: bounds.width - 20,y: 50))
path.lineWidth = 1
UIColor.blackColor().setStroke()
path.stroke()
}
你可以把一些代碼... !!!! –