Bibi's DevLog ๐Ÿค“๐ŸŽ

[iOS] UINavigationController - viewControllers์™€ pushViewController(_:animated:) ๋ณธ๋ฌธ

๐Ÿ“ฑ๐ŸŽ iOS/๐Ÿ Apple Developer Documentation

[iOS] UINavigationController - viewControllers์™€ pushViewController(_:animated:)

๋น„๋น„ bibi 2022. 12. 12. 21:28

navigationController.viewControllers

Apple Developer Documentation

  • ํ˜„์žฌ navigation stack์— ์กด์žฌํ•˜๋Š” VC๋“ค์„ ๋‚˜ํƒ€๋‚ธ๋‹ค.
    • rootVC๋Š” 0๋ฒˆ์งธ ์ธ๋ฑ์Šค ์š”์†Œ
    • ๋งจ ์œ„์— ์Œ“์ธ VC๋Š” ๋งจ ๋ ์ธ๋ฑ์Šค์˜ ์š”์†Œ (index n-1)
    • back view๋Š” index n-2
  • ํ•ด๋‹น ํ”„๋กœํผํ‹ฐ์— ์ƒˆ ๋ทฐ์ปจ ๋ฐฐ์—ด์„ ํ• ๋‹นํ•˜๋Š” ๊ฒƒ์€, setViewControllers(_:animated:) ๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๊ฒƒ๊ณผ ๊ฐ™๋‹ค.

self.navigationController.viewControllers = [issueVC] ์™€ ๊ฐ™์ด ํ• ๋‹นํ•˜๋ฉด, ๊ธฐ์กด์— ์กด์žฌํ•˜๋˜ navigation stack์„ ๋ฌด์‹œํ•˜๊ณ  ์ƒˆ ๋ทฐ์ปจ์„ ํ• ๋‹น

  • ๋”ฐ๋ผ์„œ ๋‹ค์Œ ํ™”๋ฉด์œผ๋กœ ๋„˜์–ด๊ฐ€๋„ back๋ฒ„ํŠผ์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค
  • ์™œ? ๊ธฐ์กด stack์„ ์—†์•ด์œผ๋ฏ€๋กœ ํ˜„์žฌ ํ™”๋ฉด๋ฐ–์— ์—†๋Š” ์ƒํƒœ์ž„ - ๋Œ์•„๊ฐˆ ํ™”๋ฉด ์Šคํƒ์ด ์—†์Œ
  • ๊ทธ๋Ÿฌ๋ฏ€๋กœ pushVC๋ฅผ ํ†ตํ•ด ํ™”๋ฉด์ „ํ™˜์„ ํ•˜๋Š” ๊ฒƒ์ด ๋ฐ”๋žŒ์งํ•˜๋‹ค

pushViewController(_:animated:)

Apple Developer Documentation

navigation stack์— VC๋ฅผ ๋ฐ€์–ด๋„ฃ๊ณ , ํ™”๋ฉด์„ ๊ฐฑ์‹ ํ•œ๋‹ค.

  • viewController : ์Šคํƒ์— ๋„ฃ์„ VC. tab bar controller ๊ฐ์ฒด๋Š” ๋„ฃ์„ ์ˆ˜ ์—†๋‹ค. ํ•ด๋‹น ๋ทฐ์ปจ์ด ์ด๋ฏธ navigation stack์— ์žˆ๋‹ค๋ฉด, ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.
    • ์ „๋‹ฌ๋œ VC๋Š” navigation stack์˜ top view controller๊ฐ€ ๋œ๋‹ค.
  • animated : ํ™”๋ฉด ์ „ํ™˜์— ์• ๋‹ˆ๋ฉ”์ด์…˜ ํšจ๊ณผ๋ฅผ ๋„ฃ์„์ง€ ์•ˆ๋„ฃ์„์ง€ ์ง€์ •
    • ์‹คํ–‰ ์‹œ์ ์— navigation controller๋ฅผ ์„ค์ •ํ•œ๋‹ค๋ฉด false๋กœ ์ง€์ •ํ•ด์•ผ ํ•œ๋‹ค
  • ํ™”๋ฉด์„ ์ „ํ™˜ํ•˜๋ฉด์„œ navigation bar์™€ tool bar๋„ ๋”ฐ๋ผ์„œ ๊ฐฑ์‹ ํ•ด ์ค€๋‹ค.