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