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

[FEAT] iOS 파트 1차 과제 #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

[FEAT] iOS 파트 1차 과제 #2

wants to merge 2 commits into from

Conversation

ZaidKang
Copy link
Contributor

@ZaidKang ZaidKang commented Apr 8, 2022

🌱 작업한 내용

  • 로그인 화면 UI 구성
  • 회원가입 화면 UI 구성
  • 완료 화면 UI 구성
  • 화면간 전환
  • 데이터 전달

🌱 PR Point

  • 버튼을 드래그해도 Ibaction이 먹히지 않고 속성에 exit로 홀딩되어 있어서 새로 삭제하고 view 를 다시 만들었는데 무엇을 잘못 건드린건지 궁금합니다.(새로 버튼을 만들어도 똑같이 홀딩되어 있는것으로 짐작컨대 viewController 를 잘못 건드린것 같습니다.)

  • 완료 화면에서 로그인 화면으로 dismiss 하기 위해 popToRootViewController 메소드를 사용했는데 동작하지 않았습니다. 이전 view에서의 전달 방식이 present 방식이라 Navigation Controller가 없어서 그런거라고 해서 ThirdViewController에서 프로퍼티에 주입하여 구현하였습니다.

  • 아직 swift의 naming convention을 잘 모르겠어서 다시보니 naming이 너무 클린코드에 저해되는 것 같습니다. naming convention 관련해서도 조언주시면 감사할 것 같습니다.

  • iOS는 처음이라 너무 기초적인 것도 헷갈려서 간단한거라도 피드백 해주시면 감사하겠습니다. :)

📸 스크린샷

구현 내용 스크린샷
로그인 화면 Simulator Screen Shot - iPhone 13 - 2022-04-09 at 01 18 31
회원가입 화면(1) Simulator Screen Shot - iPhone 13 - 2022-04-09 at 01 20 34
회원가입 화면(2) Simulator Screen Shot - iPhone 13 - 2022-04-09 at 01 20 40
완료 화면 Simulator Screen Shot - iPhone 13 - 2022-04-09 at 01 20 17

📮 관련 이슈

[Property] Secure Text Entry 속성 적용,
[Action] 로그인 -> 완료 화면전환(present)
Copy link
Member

@dev-jungbin dev-jungbin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR에 올려 주신 내용들 위주로 코드 리뷰 달아 놨으니 참고 부탁드려용~~~~!!
수고하셨습니다 😎


import UIKit

class FirstViewController: UIViewController {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아직 swift의 naming convention을 잘 모르겠어서 다시보니 naming이 너무 클린코드에 저해되는 것 같습니다. naming convention 관련해서도 조언주시면 감사할 것 같습니다.

ViewController의 네이밍은 화면의 용도에 따라 정하는 것이 좋습니다~~!
이를테면 로그인 화면은 SignInViewController, 환영합니다 화면은 WelcomeViewController 등등..~

ViewController라는 단어가 너무 길어서 VC로 줄여 쓰기도 합니당~ 근데 이건 협업 시 합의가 필요한 부분임~

Comment on lines +28 to +36
/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 ViewController를 상속받는 Class를 생성하면 무조건 생기는 주석이니 안 쓰신다면 지우셔도 좋습니다~~~~!!

self.welcome.text = name
}

@IBOutlet weak var welcome: UILabel!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아직 swift의 naming convention을 잘 모르겠어서 다시보니 naming이 너무 클린코드에 저해되는 것 같습니다. naming convention 관련해서도 조언주시면 감사할 것 같습니다.

요 ViewController에서 프로퍼티는 var name(.. 이걸 머라고 하져) 같은 애들과, @IB가 붙은 스토리보드에서 끌어온 친구들이 있습니다~~!

@IBOutlet weak var welcome: UILabel!
같은 경우는 welcome이라는 이름이 welcome string인지, welcome UILabel인지 구분하기 어렵다는 그런 함정이 있으니
암묵적으로~! UI 프로퍼티의 경우엔 welcomeLabel 처럼 뒤에 UI component의 종류를 붙이는 그런 암묵적 컨벤션이 있씁니다..

아마 세미나 실습 코드르를 함 보시면 welcomeLabel, completeButton, logoImageView 등의 형식인 네이밍이 보이실 거예여~~~

guard let nextVC = self.storyboard?.instantiateViewController(withIdentifier: "FourthViewController") as? FourthViewController else { return }

guard let name = name else { return }
nextVC.name = "\(name)님, 인스타그램에 오신것을 환영합니다."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기에서는 진짜 이름 name 그 자체만 넘기고, ~ 님 인스타그램에 오신 것을 환영합니다는 FourthViewController에서 처리하는 게 어떨까요!??~
만약 디자인이 바뀌어서 들어가는 텍스트가 달라졌을 경우,, Fourth의 텍스트지만 Third에서 처리해야 한다는 고런 일이 벌어질 것 같습니다~~~!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그렇네요. param 만 넘기고 커먼코드는 해당 controller에서 처리하는게 더 깔끔해보입니다!

nextVC.name = "\(name)님, 인스타그램에 오신것을 환영합니다."
nextVC.navigation = self.navigationController

self.present(nextVC, animated: true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 이 ThirdViewController에는 NavigationController가 있으니, presentself.moveToRootViewController를 실행해 주면 처리가 될 것 같습ㄴㅣ다~~ 다른 코멘트에서도 달아 놨던 내용이에요!!

Copy link

@noah0316 noah0316 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

버튼을 드래그해도 Ibaction이 먹히지 않고 속성에 exit로 홀딩되어 있어서 새로 삭제하고 view 를 다시 만들었는데 무엇을 잘못 건드린건지 궁금합니다.(새로 버튼을 만들어도 똑같이 홀딩되어 있는것으로 짐작컨대 viewController 를 잘못 건드린것 같습니다.)

  • 가장 흔한 원인은 다음과 같습니다! 드래그 앤 드롭을 시도하는 스토리보드와 뷰컨트롤러가 연결되어있는지
    Inspector Area에서 확인해주세요!! 연결이 잘되어있다면 드래그 앤 드롭 할 때 속성이 exit으로 홀딩되어 있지 않을겁니다!!

  • 다음에도 혹시 연결관계를 잘 확인했는데도 같은 문제가 생긴다면 클린빌드(cmd + shift + k)를 해보신 후에 실행해보세요!!

  • 이래도 안된다면?? 진리의 Xcode 껐켰을... 이래도 안된다면?!

  • 도움이 될진 모르겠지만 저를 불러주세요!! 같이 확인해봅시다!

완료 화면에서 로그인 화면으로 dismiss 하기 위해 popToRootViewController 메소드를 사용했는데 동작하지 않았습니다. 이전 view에서의 전달 방식이 present 방식이라 Navigation Controller가 없어서 그런거라고 해서 ThirdViewController에서 프로퍼티에 주입하여 구현하였습니다.

리뷰 : #2 (comment)
#2 (comment)

Comment on lines +20 to +24
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

self.welcome.text = name
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

viewWillAppear() 에서 초기 UI를 설정해주셨네요!!

viewDidLoad()는 현재 SecondViewController부모 클래스 인 UlViewController 클래스에 정의되어 있는 메소드입니다.

이 친구가 호출되는 시점은 뷰 컨트롤러가 뷰 계층 구조를 메모리에 로드한 후에 호출이 됩니다!!

→ 뷰 계층 구조를 메모리에 로드를 했다는 것은? → 현재 우리가 접근하려고 하는 UI 객체가 메모리에 로드 되었다는 것을 의미합니다. 따라서 일반적으로 리소스를 초기화하거나 초기 화면을 구성하는 등, 처음 한 번만 실행해야 하는 초기화 코드는 대부분 viewDidLoad() 내부에서 호출해줍니다.

Apple 공식문서에서도 → viewDidLoad() 에서 로드된 뷰에 대한 추가적인 초기화를 일반적으로 이곳에서 진행한다고 하니 이곳에서(viewDidLoad()) 초기 UI 설정을 해주는게 좋아보이네요!!
문서 링크 : 링크

ViewController의 생명주기를 같이 공부해보는 것도 좋을 것 같아 사진 첨부합니다~!

Screen Shot 2022-04-11 at 17 31 09


class FourthViewController: UIViewController {
var name: String?
var navigation: UINavigationController?
Copy link

@noah0316 noah0316 Apr 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screen Shot 2022-04-11 at 18 03 04

iOS에서 윈도우 객체는 하나의 뷰 컨트롤러를 루트 뷰 컨트롤러로 지정하여 참조합니다.

우리가 그동안 세미나를 진행하면서 여러개의 스토리보드를 만들고 info.plist에서 스토리보드의 이름을 바꿔주었었죠??

Screen Shot 2022-04-11 at 18 03 59

여기서 이렇게 시작하는 스토리보드를 지정해주는 이유는 간단히 이렇게 생각하시면 좋을 것 같습니다!!

갑분 상황극 죄송합니다..

iOS : 윈도우 객체의 루트 뷰 컨트롤러로 지정하고 싶은 뷰컨트롤러가 있는 스토리보드는 어디야?

나 : Main 스토리보드에있어~

iOS : 그럼 Main 스토리보드에 여러개의 뷰컨트롤러가 있을 수 있는데, 시작점이 되는 뷰 컨트롤러는 어디야?

나 : 여기야~

Screen Shot 2022-04-11 at 18 04 44

이렇게 윈도우 객체의 루트 뷰 컨트롤러를 지정해주고 나면 iOS는 이 NavigationController부터 앱을 시작하게 됩니다!

자 여기까지 서론이었습니다!!

다시 돌아와서 UIViewController의 extension을 보면 속성으로 navigationController가 있음을 확인할 수 있습니다.

extension이니 모든 UIViewController가 가지는 속성이겠죠?

Screen Shot 2022-04-11 at 18 05 43

주석을 보면 If this view controller has been pushed onto a navigation controller, return it.

이 속성은 해당 뷰 컨트롤러를 navigationController에 push한 친구를 반환해주는데요,

우리앱의 첫 시작점은 UINavigationController였습니다.

(window 객체의 루트 뷰 컨트롤러)

이곳에서 지정해주었죠!

Screen Shot 2022-04-11 at 18 06 11

또 Navigation Controller의 루트 뷰 컨트롤러로 로그인 화면이 있는 뷰 컨트롤러를 지정해주었습니다.

따라서 이 뷰 컨트롤러가 push 하는 모든 뷰 컨트롤러는 속성으로 바로 이 Navigation Controller를 가지고 있을 것입니다!

}

@IBAction func moveThirdController(_ sender: Any) {
guard let nextVC = self.storyboard?.instantiateViewController(withIdentifier: "ThirdViewController") as? ThirdViewController else { return }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nextVC보다는 뷰 컨트롤러의 이름으로 명시해주는게 가독성을 향상하는데 더 좋을 것 같아요!!


guard let name = inputEmail.text else { return }
nextVC.name = "\(name)님, 인스타그램에 오신것을 환영합니다."
nextVC.navigation = self.navigationController

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위의 내용과 같습니다~!!

nextVC.name = "\(name)님, 인스타그램에 오신것을 환영합니다."
nextVC.navigation = self.navigationController

self.present(nextVC, animated: true)
Copy link

@noah0316 noah0316 Apr 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

완료 화면에서 로그인 화면으로 dismiss 하기 위해 popToRootViewController 메소드를 사용했는데 동작하지 않았습니다. 이전 view에서의 전달 방식이 present 방식이라 Navigation Controller가 없어서 그런거라고 해서 ThirdViewController에서 프로퍼티에 주입하여 구현하였습니다.

Suggested change
self.present(nextVC, animated: true)
self.present(nextVC, animated: true) {
self.navigationController?.popToRootViewController(animated: true)
}

self.present()의 실행이 완료된 후에 실행되는 completionHandler를 이용하면 present가 된후에 -> navigationController의 stack을 rootViewController까지 pop시키기 때문에 정상적으로 작동합니다!!

이렇게 해주면 navigationController를 따로 주입해주지 않아도 되겠네요!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] iOS 1차 과제
3 participants