1
我正在试图在TableView上创建一个Progress View。如何在TableView中创建进度视图?
我成功创建了progressview,但是如果动画是真的,bar会消失,如果false bar已满......我无法理解为什么。
这是我的代码:
这里是我的追加方法:
if formazione == formazione {
guestInfoList.append("Formazione: \(formazione)%")
}
这里全出列功能:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var countdowncell = tableView.dequeueReusableCell(withIdentifier: "countdowncell", for: indexPath)
//countdown
if indexPath.row == 9{
countdowncell.textLabel?.text = calcolaCountdown()
}else{
countdowncell.textLabel?.text = guestInfoList[indexPath.row]
}
//Creazione Progress View
if indexPath.row == 12 {
cell = UITableViewCell(style: .default, reuseIdentifier: "Cell")
let progressView = UIProgressView(progressViewStyle: .default)
//setting height of progressView
let transform = CGAffineTransform(scaleX: cell.frame.size.width, y: cell.frame.size.height)
progressView.transform = transform
cell.contentView.addSubview(progressView)
//**//inserisci valore formazione
progressView.setProgress(Float(formazione), animated: false)
}
return countdowncell
}
PS:如果我想把进度在单元右侧查看?
编辑
最后我成功了!谢谢亚光!
if indexPath.row == 12 {
var cell = tableView.dequeueReusableCell(withIdentifier: "formprogresscell", for: indexPath)
let progressView = UIProgressView(progressViewStyle: .default)
//setting height of progressView
progressView.frame = CGRect(x: 230, y: 20, width: 130, height: 130)
progressView.progress += 0.5
progressView.rightAnchor.accessibilityActivate()
//**//inserisci valore formazione
progressView.setProgress(Float(formazione), animated: true)
progressView.progressTintColor = UIColor.red
cell.textLabel?.text = "Formazione: \(formvalue)%"
cell.contentView.addSubview(progressView)
}
'cell = UITableViewCell('这完全错了,你应该从头开始创建自己的单元格,你应该问表格视图来'出列'一个单元格如果你已经正确地实现了'cellForRowAt',你已经完成了,使用这个单元格,而不是一个不同的单元格。 – matt
谢谢你回答我这么快马特,我要编辑为更清晰的问题,坚持下去 –
你还在做我刚才告诉你不要做的事,你用一个全新的单元替换出队的单元,不要,用一个不同的标识符的单元很好,但你应该请问表格视图,而不是自己创建它。 – matt