Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation Controller를 사용할 때 title 설정 방법 #247

Closed
shp7724 opened this issue Aug 29, 2021 · 2 comments
Closed

Navigation Controller를 사용할 때 title 설정 방법 #247

shp7724 opened this issue Aug 29, 2021 · 2 comments
Labels
iOS iOS 관련 내용 question 질문으로 사용될 이슈
Milestone

Comments

@shp7724
Copy link
Collaborator

shp7724 commented Aug 29, 2021

안녕하세요. iOS 세미나 수강생 박신홍입니다.

오늘 세미나에서 navigationController?.title = "Waffle Studio" 코드가 잘 작동하지 않았었는데요.
그 이유가 궁금해서 조금 찾아보니 Navigation Controller(이하 NC)에 대한 감이 조금 잡히는 것 같아서, 제가 이해한 내용을 공유할 겸 잘못 이해한 부분이 있다면 바로잡기 위해 이슈로 남기게 되었습니다.

아래 내용 중 틀린 부분이 있다면 바로잡아주시고, 없으면 바로 close 해주셔도 될 것 같습니다!


1. NC는 눈에 보이는 화면이 아니다.

image
NC를 임베드하면 위와 같이 스토리보드 상에 화면이 하나 추가되지만, 이것은 실제로 눈에 보이는 화면이 아닙니다.

2. NC에서 출발하는 화살표의 의미

image
NC의 계층 구조가 Linked List로 구현한 Stack과 유사하다는 느낌을 받았습니다. NC 자체는 첫 번째 원소(i.e. 화면)의 객체 주소를 담고 있는 Head 변수와 비슷한 역할인 것 같고, 오른쪽에 있는 화면일수록 Stack에서 가장 마지막에 쌓이는 원소에 대응한다고 보면 될 것 같습니다.

3. NC의 title 설정 방법

위의 내용을 종합하면, NC 자체는 눈에 보이는 화면이 아니기 때문에 navigationController?.title = "Waffle Studio"와 같이 NC 자체의 title을 설정해주는 것은 의미가 없고, NC에 속한 원소들, 즉 화면들 각각의 UIViewControllerviewDidLoad 메서드에서 title = "Waffle Studio"를 하나씩 선언해주어야 하는 것 같습니다. 예를 들어, NC라는 Stack에 속한 원소가 10개라면, 10개의 뷰 컨트롤러 각각에서 title을 따로 설정해주어야 합니다.

여기까지 제가 잘 이해한 것이 맞는지 봐주시면 감사하겠습니다!

@shp7724 shp7724 added iOS iOS 관련 내용 question 질문으로 사용될 이슈 labels Aug 29, 2021
@shp7724 shp7724 added this to the seminar 0 milestone Aug 29, 2021
@shp7724 shp7724 assigned keumartist and unassigned keumartist Aug 29, 2021
@keumartist
Copy link
Member

Navigation controller에 대한 좋은 이슈 남겨 주셔서 감사합니다!

'1. NC는 눈에 보이는 화면이 아니다' 라고 하신 말을 맞는 말인 것 같습니다. NC는 눈에 보이는 view들을 연결한 view controller들을 관리하는 container view controller 입니다. view controller들 뿐만 아니라 navigation bar 라는 객체도 관리를 하지요.

그런데 NC로 관리되는 view controller들은 linked list가 아닌 array(NSArray)로 구현된 stack에 들어갑니다. stack 안에서 현재 보이는 view의 controller가 top에 위치하게 되고, root view의 controller가 bottom에 위치하게 됩니다.

Screen Shot 2021-08-30 at 8 33 54 PM

실습을 할때 navigationController?.title = "waffle studio"가 view에 반영되지 않았던 것은, navigationController?.title과 연결된 view가 없기 때문입니다. 사실 제가 하려던 것은 navigationItem?.title = "waffle studio" 이었고, navigationItem은 해당 view controller와 연결된 view이기 떄문에 반영이 됩니다. 찾아주신 것처럼 ViewController의 property인 title = "waffle studio" 로 작성해도 타이틀이 반영이 됩니다. title과 navigationItem.title 중 무엇을 쓰는게 더 좋은지 생각해 봤는데, navigation controller 안에서는 의미상 navigationItem.title 가 더 정확하지만, title을 사용하면 tabbar controller를 쓰던 navigation controller를 쓰던 알아서 맞춰서 타이틀이 반영되어서 편합니다. 어떤 것을 써도 상관 없을 것 같습니다.

그런데 view가 연결되지 않은 navigationController?.title가 존재했던 이유는, NC가 view controller를 상속하기 때문입니다. 제 생각으로는 이게 상속의 단점 중에 하나인 것 같습니다. 필요 없는 property까지 상속을 해버린 거지요.

Navigation Controller에 대한 자세한 내용은 아래 링크를 참고하시면 됩니다!
https://developer.apple.com/documentation/uikit/uinavigationcontroller

@shp7724
Copy link
Collaborator Author

shp7724 commented Aug 31, 2021

자세한 설명 감사합니다!
이슈 Close 하도록 하겠습니다.

@shp7724 shp7724 closed this as completed Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iOS iOS 관련 내용 question 질문으로 사용될 이슈
Projects
None yet
Development

No branches or pull requests

2 participants