添加多个视图问题

时间:2017-11-24 14:37:02

标签: ios swift uiview uipageviewcontroller slide

我自己做了slideView。它只是一个小UIPageViewController内部,有一个UILabel,我不断使用计时器为其添加值。但我意识到,当我在slideView中添加新值时,它不会删除旧视图。它在旧版本上添加了新标签。这真的很有趣。它还会导致内存使用率过高。如何删除旧的并添加新的?

这是我的代码:

func createSlide() ->[CountdownView]{
    var slideAll = [CountdownView]()

    for i in 0..<countdownDatas.count{
        slideAll.append(Bundle.main.loadNibNamed("CountdownView", owner: self, options: nil)?.first as! CountdownView)

        slideAll[i].countdownLabel.text = "\(countdownDatas[i].month)\(countdownDatas[i].week)\(countdownDatas[i].day)\(countdownDatas[i].hour)\(countdownDatas[i].minute)\(countdownDatas[i].second)"
    }
    return slideAll

}

您可以在此图片上看到问题: enter image description here

我意识到当我为视图和标签清除背景颜色时。

解决方案:

感谢@ReinierMelian,我找到了解决方案。这是工作代码:

    func createSlide() ->[CountdownView]{
        if firstTimeSlideViewSetup == true{
            firstTimeSlideViewSetup = false
            for i in 0..<countdownDatas.count{
                slideAll.append(Bundle.main.loadNibNamed("CountdownView", owner: self, options: nil)?.first as! CountdownView)

                slideAll[i].countdownLabel.text = "\(countdownDatas[i].month)\(countdownDatas[i].week)\(countdownDatas[i].day)\(countdownDatas[i].hour)\(countdownDatas[i].minute)\(countdownDatas[i].second)"
}
        }else{
            for i in 0..<countdownDatas.count{

                slideAll[i].countdownLabel.text = "\(countdownDatas[i].month)\(countdownDatas[i].week)\(countdownDatas[i].day)\(countdownDatas[i].hour)\(countdownDatas[i].minute)\(countdownDatas[i].second)"

            }
        }

        return slideAll

    }

基本上,当我第一次创建slideView时,我说我创建了这个,然后我正在检查是否有slideView。然后我只是在标签上添加新值。

0 个答案:

没有答案