SWIFT - 为什么水平滚动视图和功能不起作用

SWIFT - Why Horizontal Scroll View and Feature does not work

我一直在学习这个教程:https://www.youtube.com/watch?v=Vq71SPkJIus 但由于某种原因,模拟器中什么也没有出现,也没有错误,它只是说 "Thread 1: breakpoint 1.1",这是一个错误吗?抱歉,我对此很陌生,不太确定

我检查了所有代码以确保它是正确的,但我不确定该怎么做,或者我做错了什么

@IBOutlet weak var pageControl: UIPageControl!
    @IBOutlet weak var slideScrollView: UIScrollView!
    override func viewDidLoad() {
        super.viewDidLoad()

        slideScrollView.delegate = self
        let slides:[Slide] = createSlides() //THREAD 1: BREAKPOINT 1.1
        setupScrollView(slides: slides)
        pageControl.numberOfPages = slides.count
        pageControl.currentPage = 0
        // Do any additional setup after loading the view, typically from a nib.
    }

    func createSlides() -> [Slide] {
        let slide1:Slide = Bundle.main.loadNibNamed("Slide", owner: self, options: nil)?.first as! Slide
        slide1.label.text = "Slide1"

        let slide2:Slide = Bundle.main.loadNibNamed("Slide", owner: self, options: nil)?.first as! Slide
        slide2.label.text = "Slide2"

        return [slide1, slide2]
    }

    func setupScrollView(slides:[Slide]) {
        slideScrollView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.width)
        slideScrollView.contentSize = CGSize(width: view.frame.width * CGFloat(slides.count), height: view.frame.height)
        slideScrollView.isPagingEnabled = true

        for i in 0 ..< slides.count {
            slides[i].frame = CGRect(x: view.frame.width * CGFloat(i), y: 0, width: view.frame.width, height: view.frame.height)
            slideScrollView.addSubview(slides[i])
        }
    }

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let pageIndex = round(scrollView.contentOffset.x/view.frame.width)
        pageControl.currentPage = Int(pageIndex)
    }

这是你看到的吗?

如果是这样,您只是在代码的某些部分启用了断点。

只需点击此按钮即可将其禁用

如果您是开发新手,只需在 Xcode 或任何其他 IDE 上查找有关如何调试代码的教程以掌握它,您将学到很多很酷的东西这被认为是显而易见的,但事实并非如此。这些东西将帮助您走上成为优秀开发人员的道路。祝你好运!

然后点击播放继续