영삼이의 IT정보2012. 4. 28. 16:46

xcode 4.2를 사용하다가 4.3을 사용하니 MainWindow.xib 가 없어서

MainWindow.xib 를 사용하여 프로젝트를 시작하는 방법을 정리한다.


  • xcode 4.3 empty project로 새 프로젝트를 생성
  • NewFile → User Interface → Window → ... → MainWindow 로 저장
  • AppDelegate.h 파일에 아래와 같이 IBOutlet을 추가
    • @property (strong, nonatomic) IBOutlet UIWindow *window;
  • MainWindow.xib 를 클릭하여 Interface Builder 에서 아래와 같이 작엄
    • Objects 항목에다가 우측 Library에서 Object를 끌어다 놓기
    • Objects 항목에다가 우측 Library에서 Window 끌어다 놓기
    • 끌어다 놓은 Object 선택하고 Identity Inspector 에서 Class 를 해당하는 xxxAppDelegate 로 변경
    • File's Owner 선택하고 Identity Inspector 에서 Class 를 UIApplication 으로 변경
      • File's Owner 선택하고 Connections Inspector 에서 Outlets 의 delegate를 xxx App Delegate 로 연결
      • Objects에서 xxx App Delegate 를 선택하고 Connections Inspector 에서 rootController, window를 연결
        • 여기서 rootController 는 사용하고자 하는 ViewController 를 미리 만들어 놓아야 함(아래 그림에서는 TabBarController)
    • Project Targets 세팅에서 Main Interface를 MainWindow로 적어준다
    • AppDelegate.m 의 초기 코드를 아래와 같이 변경 (window를 위에서 IBOutlet으로 변경했으므로 alloc 제거)
      • //self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

        // Override point for customization after application launch.

        //self.window.backgroundColor = [UIColor whiteColor];


        self.window.rootViewController = rootController;

        [self.window addSubview:rootController.view];


        [self.window makeKeyAndVisible];


    ※ 위 방법은 Beginning iPhone4 Development 책에서 사용하는 방식을 Xcode 4.3 에서 세팅하는 것이다.

    꼭 위와 같이 시작할 필요는 없으며, 시작하는 코드에 ViewController를 alloc 하여 AppDelegate가 멤버로 가지고 있는 window에 rootController로 지정해서 시작해도 될 것이다. 해당 ViewController 의 viewDidLoad 등의 함수에서 초기 화면을 세팅하면 된다.

    Posted by 다오나무