I have a UITableView with UITableViewCell. And in UITableViewCell I have a custom view which draw a circle inside if it needed.
But when I scroll this circles change positions, disappears and so on. Can't understand why so...
You can see what happens after 3 times of scrolling down-up:
So the right positions of circles were missed.
That is my storyboard screenshot for this view:
The class of my custom view which draws the circle:
class SongRatingView: UIView {
var ratingVal: Float?
var circleCenter: CGPoint {
return convertPoint(CGPoint(x: center.x, y: center.y), fromView: superview)
}
var circleRadius: CGFloat {
return min(bounds.size.width, bounds.size.height) / 2 - 1
}
var strokeColor: UIColor?
override func drawRect(rect: CGRect) {
guard strokeColor != nil else {
return
}
let circlePath = UIBezierPath(arcCenter: circleCenter, radius: circleRadius, startAngle: 0, endAngle: CGFloat(2 * M_PI), clockwise: true)
strokeColor!.setStroke()
circlePath.lineWidth = 1
circlePath.stroke()
}
}My cellForRowAtIndexPath method:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("songCell", forIndexPath: indexPath) as! SongsTableViewCell
let song = songs![indexPath.row]
cell.songNameLabel.text = song.nameDecoded
cell.delegateOpt = self
cell.cellIndexOpt = indexPath.row
cell.authorNameLabel.text = song.author?.nameDecoded
cell.songRatingLabel.text = ""
cell.songRatingView.strokeColor = nil
if let songRating = song.rating?.floatValue {
if songRating > 0 {
cell.songRatingLabel.text = String(songRating / 10)
cell.songRatingLabel.textColor = UIColor.purpleColor()
cell.songRatingView.strokeColor = UIColor.purpleColor()
}
}
return cell
}And finally I have in class SongsTableViewCell:
@IBOutlet weak var songRatingView: SongRatingView!which connected with storyboard
Update: Don't know why pictures I past ino post does not displayed....