swiftviewscrollpagination

SWIFT - Why Horizontal Scroll View and Feature does not work


I was following this tutorial: https://www.youtube.com/watch?v=Vq71SPkJIus but for some reason nothing is appearing in the simulator and there are no errors, it just says "Thread 1: breakpoint 1.1", is that an error? Sorry I'm pretty new to this and not really sure

I checked all the code to make sure it is right and it is so not sure what to do, or what I did wrong

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

Solution

  • is this what you are seeing?

    breakpoint

    If that's the case, you just enabled a breakpoint in some part of your code.

    just tap this to disable it

    enter image description here

    If you are new to development, just look for tutorials on how to debug code on Xcode or any other IDE to get the grasp of it, you will learn a lot of cool stuff that's taken as obvious, but it really isn't. Those things will help you out your path of becoming a great developer. Good Luck!

    and click play to continue enter image description here