Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.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
Xcode swift3标签上UIprogress视图的进度_Xcode_Swift3_Ios10 - Fatal编程技术网

Xcode swift3标签上UIprogress视图的进度

Xcode swift3标签上UIprogress视图的进度,xcode,swift3,ios10,Xcode,Swift3,Ios10,我试图使用以下代码在标签上显示swift3中progressview的进度,但是进度被卡在10%上,无法继续。 请帮忙 override func viewDidLoad() { super.viewDidLoad() Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(myprogressview),userInfo: nil, repeats: true) } func mypro

我试图使用以下代码在标签上显示swift3中progressview的进度,但是进度被卡在10%上,无法继续。 请帮忙

override func viewDidLoad() {
    super.viewDidLoad()


   Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(myprogressview),userInfo: nil, repeats: true)
}

func myprogressview(timer : Timer)
{

    var count : Int = 0
    count += 1

    if (count <= 10)
    {
        Progress1.progress = Float(count)/10.0
        progressLabel.text = String.init(format: "%d %%", count*10)

    }

    timer.invalidate()
}

您必须在else条件下使计时器无效,因为当函数调用first time timer invalidate时,计时器将无效,并且在myprogressview函数之外声明计数,因为每次它变为零

 var count : Int = 0
    func myprogressview(timer : Timer)
    {
        count += 1

        if (count <= 10)
        {
            print(count*10)
            progress.progress = Float(count)/10.0
            progressLable.text = String.init(format: "%d %%", count*10)

        } else {

         timer.invalidate()
        }


    }

您使“myprogressview”主体中的停止计时器无效,因此它将永远不会超过您第一次调用它的时间,因此它将在10%中的1%停止。仅当“计数==10”时,才使计时器无效。此外,“count”每次都将重置为0,因为它是一个局部变量。