강좌라기 보다는 내가 배우면서 찾아본 자료는 최신버전의 강좌가 없어서 
설정이나 메뉴구성이 미묘하게 다른 부분에 다른초보분들이 망설이지 않고 따라할수 있게..
이건 핑계고 걍 이런거라도 남기면서 하면 좀더 재미있을까 하는...

이번편의 목적은 윈도우 베이스의 어플에 뷰를 추가하는 과정을 해봄으로서 뷰나 기타 라이브러리의 추가에
익숙해지기 위해서 이다.

실행환경은 Xcode 3.2.4

순서는
1. 프로젝트 생성
2. 클래스파일 생성
3. 클래스파일 코딩
4. 인터페이스 빌더 작업
5. 완성

1. 프로젝트 생성
새프로젝트 생성에서 Window-based Application  선택

2. 클래스 파일 생성
생성하고자 하는 폴더 위에서 마우스 우클릭후 Add - New File.. 선택

UIViewController 를 선택

위에 클래스명을 적당히 적어주고 바로 밑의 Also Create 를 체크한다
언제나 그렇듯 명명은 중요하다 적당히 잘 적어넣자.
피니쉬 버튼을 누르면 3개의 파일이 생성된다.
그중 확장자가 xib인 화일은 이름을 다시 바꿔주는것도 좋을듯 하다. 혼동되기 쉽다.
그리고 폴더도 class 폴더보단 Resources 폴더가 더 어울리는 것같다. 옮겨주자.

3. 소스 수정
Project명이 Test라면 프로젝트 생성시에 TestAppDelegate.h TestAppDelegate.m 파일이 생성되었을것이다.

TestAppDelegate.h  

------------------------------------------------------------------

#import <UIKit/UIKit.h>

@class WelcomeCtr;


@interface TestAppDelegate : NSObject <UIApplicationDelegate> {

    UIWindow *window;

    WelcomeCtr *welcomeCtr; //추가

}


@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet WelcomeCtr *welcomeCtr;  //추가


@end


------------------------------------------------------------------


TestAppDelegate.m


------------------------------------------------------------------


#import "TestAppDelegate.h"

#import "WelcomeCtr.h"


@implementation TestAppDelegate


@synthesize window;

@synthesize welcomeCtr;   //추가


#pragma mark -

#pragma mark Application lifecycle


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    

    // Override point for customization after application launch.

[window addSubview:welcomeCtr.view];   //추가

    [window makeKeyAndVisible];

    

    return YES;

}



- (void)applicationWillResignActive:(UIApplication *)application {

    /*

     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

     */

}



- (void)applicationDidEnterBackground:(UIApplication *)application {

    /*

     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 

     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.

     */

}



- (void)applicationWillEnterForeground:(UIApplication *)application {

    /*

     Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.

     */

}



- (void)applicationDidBecomeActive:(UIApplication *)application {

    /*

     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

     */

}



- (void)applicationWillTerminate:(UIApplication *)application {

    /*

     Called when the application is about to terminate.

     See also applicationDidEnterBackground:.

     */

}



#pragma mark -

#pragma mark Memory management


- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {

    /*

     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.

     */

}



- (void)dealloc {

[welcomeCtr release];   //추가

    [window release];

    [super dealloc];

}



@end


------------------------------------------------------------------


4. 인터페이스 빌더 작업

Overview창에서 MainWindow.xib 파일을 더블클릭하면 인터페이스 빌더가 실행된다
라이브러리창에서 View Controller 를 끌어다가 MainWindow.xib창에다 놓는다.
라이브러리창이 보이지 않는다면 인터페이스 빌더 상단 메뉴에서 View - Library를 선택한다.
이작업은 생성한 뷰객체를 넣을수 있는 공간을 마련한다고 생각하면 될듯하다.


생성된 View Controller 객체를 클릭후 상단의 파란색 Inspector 버튼을 클릭하면 오른쪽의 어트리뷰트창이 열린다.
첫번째 탭을 선택후 NIB Name 을 생성한 xib 파일명으로 선택해준다


마지막 탭을 선택후 Class에 자신이 생성한 클래스 파일을 선택해준다.

마지막 작업이다.
스샷에는 Finder App Delegate 라고 되있지만 자신의 프로젝트명 App Delegate 를 선택하고 마우스 우클릭을 하면
밑에 보이는 검은색 팝업이 열린다.
welcomeCtr 옆의 속이 비어있는 원을 클릭후 오른쪽의 Welcome Ctr 에다가 끌어다 놓는다.


잘 되었다면 아래의 화면처럼 되었을 것이다.


이걸로 끝이다 
별내용 아닌데 길어졌다.

아이폰에서 실행시켜보면 새하얀 화면이 나오는것을 확인할수 있다.
이작업이 귀찮다면 가장위의 화면에서 View-base 앱을 선택해주면 지금까지의 작업이 완료된 프로젝트가 생성된다. 
먼짓한거야...
Posted by 김반장78
,