๐ŸŽ iOS & Swift

PageViewController ์ด์Šˆ - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The number of view controllers provided (3) doesn't match the number required (1) for the requested transition'

taeeekki 2022. 8. 20. 02:22

PageViewController ์ด์Šˆ

PageViewController๋ฅผ ์ฒ˜์Œ ์‚ฌ์šฉํ•˜๋‹ค๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ด์Šˆ๋ฅผ ๋งŒ๋‚  ์ˆ˜ ์žˆ๋‹ค.
ํ•ด์„์„ ์กฐ๊ธˆ๋งŒ ํ•ด๋ณด๋ฉด ์‰ฝ๊ฒŒ ๋ฌธ์ œ๋ฅผ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

 

Issue

Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: 'The number of view controllers provided (3) doesn't match 
the number required (1) for the requested transition'

View Controller๊ฐ€ ํ•„์š” ์ด์ƒ์œผ๋กœ ํ• ๋‹น๋˜์—ˆ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.
1๊ฐœ๋งŒ ํ•„์š”ํ•œ๋ฐ 3๊ฐœ๋‚˜ ๋„ฃ์—ˆ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ๐Ÿ˜…

 


 

๊ธฐ์กด ์ฝ”๋“œ

// PageViewController.swift

import UIKit

class PageViewController: UIPageViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let firstVC = FirstViewController()
        let secondVC = SecondViewController()
        let thirdVC = ThirdViewController()
        
        setViewControllers([firstVC, secondVC, thirdVC], direction: .forward, animated: true, completion: nil)
    }
}

 


 

์ˆ˜์ • ์ฝ”๋“œ

// PageViewController.swift

import UIKit

class PageViewController: UIPageViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let firstVC = FirstViewController()
        let secondVC = SecondViewController()
        let thirdVC = ThirdViewController()
        
        // โœ…  ์ˆ˜์ • ๋ถ€๋ถ„ : ์ธ์ž๋กœ View Controller ํ•˜๋‚˜๋งŒ ์ „๋‹ฌ
        setViewControllers([firstVC], direction: .forward, animated: true, completion: nil)
    }
}