Create helloworld project via Xcode

-- iOS (iPhone) 2012. 10. 11. 15:52
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
회사 맥미니에 Xcode 4.3.3이 설치되어 있어 이를 이용해 첫 아이폰 프로젝트를 만들려고 한다.


* 프로젝트 생성

Xcode메뉴에서 File - New - Project를 선택한다.
그러면 Choose a template for your new project: 창이 나타난다.

iOS탭에서 Application을 선택하고 Utility Application을 선택 후 Next버튼을 누른다.
그러면 Choose options for your new project: 창이 나타나는데 아래와 같이 항목을 입력한다.

Product Name : firstapp
Company Identifier : com.tiger 
Class Prefix : TIGER
Device Family : iPhone (select)

Use Storyboards (check)
Use Automatic Reference Counting (check)


* 프로젝트 위치지정

적절한 폴더를 지정한 후 하단의 Source Control : Create local git repository for this project가 선택해제한다.
그리고 나서 Create버튼을 누르면 지정한 폴더에 프로젝트가 생성된다.


* 스토리보드 편집

Project Navigator에서 MainStoryboard.storyboard를 선택하면 스토리보드 편집기가 나온다. 스토리보드 편집기는 Main View Controller와 Flipside View Controller로 구성되어 있다.

앞으로의 모든 글에서 MainView Controller는 MVC, Flipside View Controller는 FVC로 명시하겠다.

Show the object library창에서 label을 선택하여 MVC에 label을 하나 추가한다. 그리고 Show the attributes inspector창에서 Text를 helloword로 변경한다. 마지막으로 Run버튼을 눌러 실행한다.


* Label Referencing Outlet

MVC에 추가한 label에서 오른쪽버튼을 눌러 팝업창이 나오는데, Referencing Outlets > New Referencing Outlet 선택하고 +버튼을 마우스로 드래그하여 TIGERMainViewController.h 소스내에 드롭한다. 그러면 팝업박스가 나오는데 거기의 Name을 label_helloworld로 입력하고 connect버튼을 누르면 아래와 같이 소스가 생성된다.

#import "TIGERFlipsideViewController.h"

@interface TIGERMainViewController : UIViewController <TIGERFlipsideViewControllerDelegate>
@property (strong, nonatomic) IBOutlet UILabel *label_helloworld;
@end


* FVC의 TextBox에 입력된 문자열을 MVC의 label에 표시

FVC에 TextBox를 하나 추가하고 위와 같은 방식으로 TIGERFlipsideViewController.h에 아래의 코드를 생성한다.

@property (strong, nonatomic) IBOutlet UITextField *edit_helloworld;


그리고나서, TIGERMainViewController.m에 아래의 내용을 코딩한다.

- (void)flipsideViewControllerDidFinish:(TIGERFlipsideViewController *)controller
{
self.label_helloworld.text = controller.edit_helloworld.text;
[self dismissModalViewControllerAnimated:YES];
}


* MVC의 label의 값을 TextBox에 로드하기

[TIGERFlipsideViewController.h]

@property (strong, nonatomic) NSString* strLabelText;


[TIGERFlipsideViewController.m]

@synthesize strLabelText = _strLabelText;

- (void)viewWillAppear:(BOOL)animated
{
self.edit_helloworld.text = self.strLabelText;
[super viewWillAppear:animated];
}


[TIGERMainViewController.m]

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"showAlternate"]) {
id flipsideViewController = [segue destinationViewController];
    [flipsideViewController setDelegate:self];
    [flipsideViewController setStrLabelText:self.label_helloworld.text];

//[[segue destinationViewController] setDelegate:self];
}
}
posted by 어린왕자악꿍