TableView의 셀에 올바른 선택 상태가 표시되는 올바른 절차는 무엇입니까? 아래 표에는 UIButton의 하위 클래스로 만든 이러한 사용자 지정 지표가 있습니다. didSelectRowAtIndexPath가 두드리면 점등과 점등 사이를 토글합니다. tableView의 dataSource는 사전의 배열이며 사전은 각 셀의 상태와 관련된 정보를 보유합니다.TableViewCells를 올바르게 업데이트하는 방법
내가 해결하려고하는 과제는 목록을 스크롤하면 잘못된 셀이 켜지거나 꺼지는 것이고 셀 재사용의 기능이라고 생각됩니다.
나는 willDisplayCellForRowAtIndexPath에 코드를 넣어 시도했습니다. 전에이 문제를 해결 한 것 같지만이 문제에 붙어 있습니다. 여기
사용자 정의 버튼 클래스
import UIKit
@IBDesignable
class WaterButton: UIButton {
@IBInspectable var fillColor: UIColor = .green
@IBInspectable var greyColor: UIColor = .gray
@IBInspectable var completed = false
let lineWidth: CGFloat = 2.0
let π = CGFloat(M_PI) //option P for π
override func draw(_ rect: CGRect) {
if completed {
drawStrokedCircle(percentRadius:0.5, color: fillColor, filled: true)
drawStrokedCircle(percentRadius:0.8, color: fillColor, filled: false)
} else {
drawStrokedCircle(percentRadius:0.5, color: greyColor, filled: false)
}
}
func drawStrokedCircle(percentRadius: CGFloat, color: UIColor, filled: Bool) {
// 1
let center = CGPoint(x:bounds.width/2, y: bounds.height/2)
// 2
let radius: CGFloat = ((max(bounds.width, bounds.height)/2.0) * percentRadius)
// 3
//let arcWidth: CGFloat = 76
// 4
let startAngle: CGFloat = 0
let endAngle: CGFloat = 2 * π
// 5
let path = UIBezierPath(arcCenter: center,
radius: radius,
startAngle: startAngle,
endAngle: endAngle,
clockwise: true)
// 6
path.lineWidth = 2.0
color.setStroke()
path.stroke()
if filled {
fillColor.setFill()
path.fill()
}
}
}
제안 해 주셔서 감사합니다. 불행히도 그것은 작동하지 않습니다. – Aaronium112