๋ฒํผ ํด๋ฆญ์ TabBar ์ด๋
์ด์ ๋ถํฐ ๊ดด๋กญํ๋ ViewController ์ด๋..! ์ ๊ฐ ํด๋์ต๋๋ค!!
์์ ๋ณด์ด์๋ ๊ทธ๋ฆผ์์ ์ ๋ ์ > ( ํ์ดํ ๋ฒํผ ) ์ ๋๋ ์ ๋ ์๋์ ๋นจ๊ฐ ํ์ดํ ์ฒ๋ผ ์ด๋ํด์ ์๋์ TodoList๋ฅผ ๋ณด์ฌ์ฃผ๊ณ ์ถ์๋ ๊ฑฐ์์ด์.
์ ๊ทธ๋ ๊ฒ ์ด๋ํด์ผํด?! ์๋๊ฐ ๋ญ์ผ?!
์ ๊ฐ ์๋ํ ์บ๋ฆฐ๋๋ just ๊ทธ ๋ ๋ด๊ฐ ์ด๋ค ๊ฑธ ํ์์ง?!๋ฅผ ๋ณด์ฌ์ฃผ๋ ๊ณต๊ฐ์ธ ๊ฑฐ์์! ์ผ์ผํ TodoList์์ ํ์ดํ๋ก ๋์ด๊ฐ๋๊ฒ ํ๋๋๊น! ์บ๋ฆฐ๋์์ ํด๋น ๋ ์ง๋ฅผ ํด๋ฆญํ๋ฉด ๋ฒํผ๊ณผ ํ ์ด๋ธ ๋ทฐ๊ฐ ์์ ์ด ๋์ง ์๊ณ , ๊ทธ๋ฅ ์ด๋ค Todo ๊ฐ ์์๊ณ , ๋๋ ๊ทธ๊ฑธ ์ด๋งํผ ํ์ด!๋ฅผ ๋ณด์ฌ์ฃผ๋ ๊ฒ์ด์ฃ ! ๊ทผ๋ฐ ์์ ํ๊ณ ์ถ์ ์ ์๊ณ ๊ทธ๋ ๋ฐ์ดํฐ๋ก ๋์ด๊ฐ๊ณ ์ถ์ ์ ์์ผ๋ ํ์ดํ๋ฅผ ๋ง๋ค์ด ์์ ๋ ๋๊ณ ! ์ถ๊ฐ๋ ๋๊ณ ! ์ฒดํฌ๋ฆฌ์คํธ๋ ๋๊ณ !, ์ญ์ ๋ ๋๋~! ์๋์ TodoList๋ก ๋์ด๊ฐ๊ณ ์ถ์๋ ๊ฒ๋๋ค.
ํด๊ฒฐ ๋ฐฉ๋ฒ
๊ตฌ๊ธ๋ง์ ์๋ฌด๋ฆฌํด๋ ๋์ค์ง ์๊ณ .. ํญ๋ฐ ์ด๋ ๊ตฌํ ์์ฒด๊ฐ ์ ์๊ฒ ๋ฒฝ์ด์์ด์! ํด๋น ViewControl์ identifier์ธ "VC"๋ก presentํ๋ ์ ๊ฐ ์๋ํ ๋ฐ๋๋ก ์์ ํ๋ฉด์ ๋ฐ๊พธ๋๊ฒ ์๋๋ผ ํ๋ฉด ์์ ์๋ก์ด VC์ ๋ง๋ค์ด์ modal ํ์์ผ๋ก ๋์ฐ๋ ๊ฒ ๋ฐ์ ๋์ง ์๋๋ผ๊ตฌ์..!!
๊ทธ๋์ ๊ฒฐ๋ก ์ ์ด๋ป๊ฒ ํ๋! ํญ๋ฐ๋ฅผ ๊ต์ฒดํ๋ ๋ฐฉ์์ผ๋ก ๊ตฌํ์ ํ์์ต๋๋ค.
์ฐ์ ํ์ฌ ํ๋ฉด์ ๋ ์๋ ํด๋น ๋ ์ง์ TodoList๋ฅผ ๋ณด์ฌ์ฃผ๋ VC์ ๋ด๋ฆฝ๋๋ค.
dismiss(animated: true, completion: nil)
๊ทธ๋ค์ TabBarController์๊ฒ ์ ๊ทผ์ ํด์ผํด์!
ํ์ฌ App์ ํ์ฑํ๋ Scene๋ค์ ๋ฐฐ์ด์ธ UIApplication.shared.connectedScenes์ ์ ๊ทผํ์ฌ ๊ทธ ์ค ๊ฐ์ฅ ์ฒ์์ ์ฐ๊ฒฐ๋ Scene์ ์ ๊ทผํฉ๋๋ค. ( ์๋ง ์ฑ์ ๋ฉ์ธ ์ฐฝ! ) ๋ฐฉ๊ธ ์ ๊ทผํ ๊ทธ Scene์ Delegate๋ฅผ ๊ฐ์ ธ์ค๊ณ , ํด๋น Delegate์ ๊ธฐ๋ณธ ์ธํฐํ์ด์ค๋ฅผ ๋ด๋นํ๊ณ ์๋ TabBarController๊ฐ ์๋ rootViewController๋ก ์ ๊ทผํ๋ ๊ฑฐ์ฃ !
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let sceneDelegate = windowScene.delegate as? SceneDelegate,
let tabBarController = sceneDelegate.window?.rootViewController as? UITabBarController else {
return
}
ํด๋น TabBar์ ์ ๊ทผํ์ผ๋ฉด TabBarCotroller์ ์คํ์ ์๋ ๋ ๊ฐ์ ํ๋ฉด ์ค 1๋ฒ ์ธ๋ฑ์ค๋ก ์ด๋ํ๊ฒ๋ ๊ตฌํํ์์ต๋๋ค. ์ ๋ 0๋ฒ์งธ์ CalenderView๊ฐ ์๊ณ , 1๋ฒ์งธ์ todolist๋ฅผ ๋ณด์ฌ์ฃผ๋ ViewController๊ฐ ์์์ต๋๋ค!
tabBarController.selectedIndex = 1
์๋ ๊ฒ ๋๋ฉด ๋~~!
๊ทผ๋ฐ ์ ๋ ๋ฌ๋ ฅ์ ํด๋ฆญํ์ ๋ ๋์ด๊ฐ๋ ๋ ์ง๊ฐ ๋ค์ todoList๋ก ๋์ด๊ฐ์ ๊ทธ ๋ ์ง์ ํด๋นํ๋ ๋ฐ์ดํฐ๋ฅผ ๋ณด์ฌ์ฃผ์ด์ผ ํ๊ธฐ ๋๋ฌธ์ ๋ฐ์ดํฐ๋ฅผ ๋๊ฒจ์ฃผ์ด์ผ ํ์ด์! ์ ๋ ์ฌ๊ธฐ์ Tabbar -> VC ์ผ๋ก ์ ๊ทผํด์ ๊ฐ์ ๋ณด๋ด์ฃผ๋ฉด ๋๋ค๊ณ ์๊ฐํ๋๋ฐ, ํ์ฌ View์ ์์ฌ์๋ stack์ tab -> navi -> vc ์ด์๊ธฐ ๋๋ฌธ์ navigation์ ํ๋ฒ ๋ ํ ๋น์ ํด์ฃผ๊ณ ์ ๊ทผ์ ํด์ผํ๋๋ผ๊ตฌ์~! ๊ทธ๋์ ์๋์ ๊ฐ์ด ๊ตฌํํ์์ต๋๋ค.
if let NavigationViewController = tabBarController.viewControllers?[1] as? UINavigationController {
let destinationVC = NavigationViewController.viewControllers[0] as! ViewControlle
guard let selectedDate = selectedDate else { return }
destinationVC.pagedate = selectedDate.toString()
}
ํด ์ฌ๊ธฐ์ ๋ ์์ฒญ๋ ์ง๋์ ๋บ์ฃ .. ์ ๊ฐ.. ใ ใ
๊ทธ๋์ ์ต์ข ์ ์ผ๋ก ๋ฒํผ์ ๋๋ ์ ๋ ํญ๋ฐ๋ฅผ ์ด๋ํ๋ฉด์ ๋ฐ์ดํฐ๋ฅผ ๋๊ฒจ์ฃผ๋ ์ฝ๋์ ๋๋ค.
@IBAction func goToButtonTapped(_ sender: UIButton) {
dismiss(animated: true, completion: nil)
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let sceneDelegate = windowScene.delegate as? SceneDelegate,
let tabBarController = sceneDelegate.window?.rootViewController as? UITabBarController else {
return
}
if let NavigationViewController = tabBarController.viewControllers?[1] as? UINavigationController {
let destinationVC = NavigationViewController.viewControllers[0] as! ViewController
guard let selectedDate = selectedDate else { return }
destinationVC.pagedate = selectedDate.toString()
}
tabBarController.selectedIndex = 1
}
ํญ ๋ฐ์์ ์ฒซ ๋ฒ์งธ ํ๋ฉด ์ค์
์ด๊ธฐ์ ๋ค์ด์ค๋ TabBar๊ฐ ๋ฌด์กฐ๊ฑด ์ ์ผ ์ผ์ชฝ์ ์๋ ํญ๋ฐ๋ก ์กํ๊ฒ ๋๋๋ฐ ์ ๋ Todo๊ฐ ๋ฉ์ธ์ด๋ค ๋ณด๋ Todo๋ก ์ด๊ธฐ ํ๋ฉด์ด ์กํ์ผ๋ฉด ์ข๊ฒ ๋๋ผ๊ตฌ์~! ์์ฃผ ์ฝ์ต๋๋ค! ์๋ก์ด TabBarController๋ฅผ ์์ฑํด์
import UIKit
class TabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
self.selectedIndex = 1
// Do any additional setup after loading the view.
}
}
์๋์ฒ๋ผ ์ฝ๋๋ฅผ ์ง์ฃผ์๋ฉด ๋์ ๋๋ค!!
์์์ ์๋ ค๋๋ฆฐ ํญ๋ฐ ์ค์ ํ๋ ์ฝ๋์ ์์ฉ๋ฒ์ ์ด๋ผ๊ณ ์๊ฐํ์ฌ ๋ผ์~!
ํ๊ณ ์ํ๋ ๋ฐ๋ฅผ ์ด๋ค์ผ๋ ์ UI๋ ๋ฐ๊พธ๋ฌ ์ด์ด ์ด๋ํ๊ฒ ์ต๋๋ค..ใ
๋ฝ์~!โจ