CoreDataからデータを保存するためのデータを表示している単一のtableViewがあります。この表は1日分のものであり、その時点で読み取られたセルによってセルがソートされます。私は保存ごとに多くの読み取り値を持っているので、セル内の別のテーブルのように見えるビュー内のサブラベルとしてすべてのデータを表示する単一のセルを持っています(セルアプローチでテーブルを置くために行っていません)。 すべてはうまいですが、場所を保存する場所を表示する痛みの図があります。私はそれが図の正しい場所にポイントを表示するが、これが表示されたら、その日のすべての時間、その図を持つすべてのセルにポイントを追加します。 追加するサブレイヤに特定のセルを指定するにはどうすればよいですか?あなたの答えを得るのでSwift:テーブルビュー内の特定のセルのサブレイヤーで、すべてのセルではありません。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let OurData = people[indexPath.row] as! UserData
let cell: CalenderDataTableViewCell = tableView.dequeueReusableCellWithIdentifier("dataCalenderCell") as! CalenderDataTableViewCell
cell.backgroundColor = GlobalColourConstants.tableViewBackground
// MARK: diagram cell
// LocationX and LocationY represent the decimal ration of how far from the origin the point is e.g. (locationX: 0.5, locationY: 0.5) = centrePoint
if let locationX: Float = OurData.painDiagramLocationX {
print("locationx \(locationX)")
if locationX == 0 {
cell.painLocationBackgroundView.layer.borderColor = GlobalColourConstants.noteColourArray[0].CGColor
cell.painLocationBackgroundView.layer.backgroundColor = UIColor.clearColor().CGColor
// This cell.painLocationImageView = nil is suppose to remove image from cells that don't have a pain diagram. However it crashes the table.
// cell.painLocationImageView = nil
} else {
let imageName = "Torso Female"
let image = UIImage(named: imageName)
cell.painLocationImageView.image = image
if let locationY: Float = OurData.painDiagramLocationY {
cell.painLocationBackgroundView.layer.borderColor = GlobalColourConstants.painColourArray[0].CGColor
cell.painLocationBackgroundView.layer.backgroundColor = GlobalColourConstants.painColourArray[0].CGColor
print("locationy \(locationY)")
let pictureOriginX = (cell.painLocationImageView.bounds.origin.x)
let pictureOriginY = (cell.painLocationImageView.bounds.origin.y)
let pointOriginX = cell.painLocationImageView.bounds.width * CGFloat(locationX)
let pointOriginY = cell.painLocationImageView.bounds.height * CGFloat(locationY)
let circleRadius = CGFloat(8)
let circlePath = UIBezierPath(arcCenter: CGPoint(x: pointOriginX,y: pointOriginY), radius: circleRadius, startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)
let shapeLayer = CAShapeLayer()
shapeLayer.path = circlePath.CGPath
//change the fill color
shapeLayer.fillColor = UIColor.redColor().CGColor
//you can change the stroke color
shapeLayer.strokeColor = UIColor.whiteColor().CGColor
//you can change the line width
shapeLayer.lineWidth = 1.0
cell.painLocationImageView.layer.addSublayer(shapeLayer)
}
}
}
ありがとう私はまた、おそらく隠されているか可視であるドットイメージを持つことができます。私は今日後であなたの提案を試みます。 – SashaZ
私はcell.painLocationImageView.layer.sublayers?.removeAll()を使用しました。これは不要なものを削除します。しかし、私がしようとしたサブレイヤを参照するにはどうすればよいですか(shapeLayer!= nil){cell.painLocationImageView.layer.sublayers?.removeAll()}それは動作しません – SashaZ