Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何在TableView中创建进度视图?_Swift_Tableview_Uiprogressview - Fatal编程技术网

Swift 如何在TableView中创建进度视图?

Swift 如何在TableView中创建进度视图?,swift,tableview,uiprogressview,Swift,Tableview,Uiprogressview,我正在尝试在TableView上创建进度视图 我成功地创建了progressview,但若动画为真,则该条消失,若为假,则该条已满。。。我不明白为什么 这是我的代码: 以下是我的附加方法: if formazione == formazione { guestInfoList.append("Formazione: \(formazione)%") } 这里是完整的出列功能: func tableView(_ tableView: UITableView, cellF

我正在尝试在TableView上创建进度视图

我成功地创建了progressview,但若动画为真,则该条消失,若为假,则该条已满。。。我不明白为什么

这是我的代码:

以下是我的附加方法:

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)
    }

问题在于在创建进度视图后如何处理它:

let progressView = UIProgressView(progressViewStyle: .default)
您未能提供
progressView
任何
。因此它没有一个。特别是,它没有宽度。因此它是无形的


给它一个框架可以解决这两个问题:给视图一个宽度,给它一个原点,这样你就可以把它放在内容视图中你想要的地方。(但实际上应该使用自动布局,而不是框架。)

cell=UITableViewCell(
那是完全错误的。你不应该从头开始创建你自己的单元格。你应该让表视图为你出列一个单元格。如果你正确地实现了
cellForRowAt
,你已经做到了。使用这个单元格,而不是另一个。谢谢你这么快就回答我,马特,我将编辑以使问题更清楚问题,等等。你仍然在做我刚才告诉你不要做的事情。你正在用一个全新的单元格替换出列的单元格。不要。可以使用具有不同标识符的单元格,但你应该向表视图询问,而不是自己创建。