2017-09-16 29 views
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) 
    } 
+0

'cell = UITableViewCell('这完全错了,你应该从头开始创建自己的单元格,你应该问表格视图来'出列'一个单元格如果你已经正确地实现了'cellForRowAt',你已经完成了,使用这个单元格,而不是一个不同的单元格。 – matt

+0

谢谢你回答我这么快马特,我要编辑为更清晰的问题,坚持下去 –

+0

你还在做我刚才告诉你不要做的事,你用一个全新的单元替换出队的单元,不要,用一个不同的标识符的单元很好,但你应该请问表格视图,而不是自己创建它。 – matt

回答

1

问题是你创建后与进步视图做什么:

let progressView = UIProgressView(progressViewStyle: .default) 

你没有给予任何progressViewframe。因此它没有一个。特别是它没有宽度。因此它是不可见的。

给它一个框架将解决你的问题:你会给视图一个宽度,你会给它一个原点,所以你可以把它放在内容视图内的任何位置。 (但事实上,你应该使用自动布局,而不是框架)