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

스토리보드와 Xib #44

Open
Brandnew-one opened this issue Jul 11, 2023 · 0 comments
Open

스토리보드와 Xib #44

Brandnew-one opened this issue Jul 11, 2023 · 0 comments
Assignees
Labels

Comments

@Brandnew-one
Copy link
Owner

스토리보드와 xib

일반적으로 스토리보드에서 여러 뷰 컨트롤러들을 만들어서 앱의 화면과 전체적인 플로우를 구성하고 table view cell, collection view cell, custom view들을 xib파일로 만들어서 사용하는데 이 둘은 정확하게 어떤 차이가 있는 것일까?

Untitled Untitled 1

우선 컴파일 이후 생성되는 파일을 확인해보면 xib 파일은 nib으로 스토리보드는 stroyboardc로 변경되는 것을 확인할 수 있다.

storyboardc 파일에 생성된 저 의문의 nib파일들은 무엇일까?

<viewController storyboardIdentifier="Test" id="hef-Go-4NS" customClass="TestViewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">

<viewController id="BYZ-38-t0r" customClass="ViewController">

안타깝게도 nib파일을 열어보는건 유로 프로그램이라 확인을 해보지 못했지만 스토리보드 파일을 소스코드로 확인해보면 viewcontroller와 view의 ID로 파일명이 생성된것을 확인할 수 있다.

Untitled 2

storyboardc 파일에 함께 생성되는 info.plist 파일을 확인해보면 아래 3개의 파일명이UIViewControllerIdentifiersToNibNames인 것을 확인할 수 있다. 그리고 해당 value 값은 storyboard ID의 값과 동일한것도 확인할 수 있다.

@IBAction func mainButtonTapped(_ sender: UIButton) {
    print("Touch Event")
    let sb = UIStoryboard(name: "Main", bundle: nil)
    let vc = sb.instantiateViewController(withIdentifier: StaticTableViewController.storyboardID)
    navigationController?.pushViewController(vc, animated: true)
  }

그럼 이제 스토리보드에서 Segue가 아닌 navigation push로 구현할 때 identifier를 설정해야 했던 이유를 명확히 알 수 있다!

그럼 xib 파일을 컴파일 했을때도 nib파일이 생성되고 스토리보드를 컴파일 했을 때도 nib파일들과 info.plist 파일이 생성되는데 그 둘의 차이는 무엇일까?

// SB
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB">
// Xib
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB">

스토리보드와 xib파일을 모두 소스코드로 확인해보면 xml로 표현된 xib파일임을 알 수 있다.

그럼 스토리보드와 xib는 무엇이 다른걸까?

Untitled 3

우리가 일반적으로 xib파일로 생성하는 cell, custom view들은 하나의 뷰 정보만 포함하고 있는 반면 스토리보드는 여러 뷰 컨트롤러 xib파일들과 뷰 관계정보들을 포함하고 있는 파일로 구성되어 있다

@Brandnew-one Brandnew-one self-assigned this Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant