1. Project 생성
  1) Create a new Xcode Project -> View based Application -> "WebCtrl" 

2. Ctrl 추가 및 구현
  1) Text Field 추가 -> UITextField  연결
  2) Web View 추가 -> UIWebView 연결 
    ㄱ. delegate를 File's Owner에 연결해야함
    ㄴ. 부모 클래스 추가 : <UIWebViewDelegate>
  3) Round button 추가 - > (IBAction) goURL 연결

3. 헤더파일 및 소스파일

@interface WebCtrlViewController : UIViewController <UIWebViewDelegate> {
IBOutlet UITextField *urlText;
IBOutlet UIWebView *webDtl;

}
- (IBAction) goURL;
...
-(IBAction) goURL
{
NSString *urlAddr = urlText.text;
 
[webDtl loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlAddr]]]; 
}

- (void)webViewDidStartLoad:(UIWebView *)webView
{
NSLog(@"Start Load"); 
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSLog(@"Finish Load"); 
}
 
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"Fail Load");
}
...






무작정 따라하기를 시작한지 2주 남짓하여 12강의 AppsNext 무료 동영상 강의를 마무리 했다.

"시작하세요 아이폰3 프로그래밍"책으로 혹자 공부를 했었으나, 한달 남짓 나간 진도는 7장... 
하지만, 뒤 돌아보면 기억되는 것이 없는 상태에서, 주위의 소개를 공부를 시작했다.

한 강의당 20분 내외이므로 그냥 듣고 지나가면 2-3일 만에 마무리 할 수 있는 내용이었지만, 책으로 공부했을 때의 경험이 있는지라 이왕 할 것 정리를 해야겠다는 생각으로 블로그에 하나하나 자세히, 맥북에서 따라해보고 그 결과를
다시 데트크탑 PC에서 블로그에 정리했다.

이렇게 하다보니 20분 정도 하나의 강의를 공부하는데 2시간 정도 걸린 듯하다.  
하지만, 그만큼 효과와 보람이 있는 듯하다.

분명히 공부한 내용은 조금 지나면 잊혀지겠지만, 기억이 나지 않을 때 이곳에 와서 확인하면 보다 쉽게 기억해내고, 나에게는 좋은 레퍼런스가 될 것이며, 혹 누군가에도 좋은 자료나 자극이 된다면 더 좋겠다. 

아이폰 개발의 역사적인 첫 발을 찍으며...

Dream Big, Start Small
Posted by 꿈을펼쳐라
,




1. Project 생성
  1) Create a new Xcode Project -> View based Application -> "EtcCtrl"

2. Control 생성 및 연결
  1) Library 창에서 원하는 Control을 View에 올려 놓음
  2) header 파일에 해당하는 함수 혹은, 변수를 추가함
  3) Source 파일에서 해당하는 함수, 혹은 변수 구현 ( 변수일 경우, release 확인)
  3) IB에서 컨트롤과 해당하는 함수, 혹은 변수와 연결 ( 함수는 컨크롤에서 File's Owner로, 변수는 File's Owenr에서 해당 컨크롤로 연결)

3. Header / Source 파일
@interface EtcCtrlViewController : UIViewController {
IBOutlet UIProgressView *neoProgress;
}

- (IBAction) segmentChange:(id)sender;
- (IBAction) switchChange:(id)sender;
- (IBAction) sliderChange:(id)sender;
- (IBAction) click1;
- (IBAction) click2;
- (IBAction) click3;


@end

...

- (IBAction) segmentChange:(id)sender
{
 NSLog(@"click index %i", [sender selectedSegmentIndex] );
}

- (IBAction) switchChange:(id)sender
{
UISwitch* tmpSwitch = (UISwitch* ) sender;
 
if(tmpSwitch.isOn){
NSLog(@"현재 켜짐");
}
else {
NSLog(@"현재 꺼짐");
}
}
 
- (IBAction) sliderChange:(id)sender
{
UISlider *slider = (UISlider *) sender; 
NSLog(@"value : %f", slider.value); //0~1 소수형
}

-(IBAction) click1
{
neoProgress.progress =0.3; 
}

-(IBAction) click2
{
 neoProgress.progress =0.6; 
}

-(IBAction) click3
{
neoProgress.progress =1.0;
}

...



[기타사항]

1. 자료형변환 :  UISlider *slider = (UISlider *) sender;  에서와 같이 "( * )"를 사용. : []를 사용해놓고 에러 때문에 30분 해멤.  헥~헥~

2. 변수 neoProgress 도 relase 해워야 할 듯. (이제 신경도 안쓰시네..)
Posted by 꿈을펼쳐라
,



1. Project 생성
  1) Create a new Xcode Project -> View based Application -> "AlertManager"

2. Action Button 연결하기
  1) Round Button 추가 -> 버튼명 설정
  2) header 파일에 함수 선언  : - (IBAction) clickButton;
  3) source 파일(*.m) 파일에 정의  : - (IBAction) clickButton;
  4) IB에서 Round Button 클릭 후 File's Owner로 오른쪽 마우스 클릭 후, Drag & Drop -> 함수연결

3.UIAlertView / UIActionSheet 사용하기
    -> 프로그램 코드 참고

4. UIAlertView / UIActionSheet 의 버튼 클릭 이벤트 사용하기
  1) Header 파일에 이벤트를 컨트롤 할 수 있는 Delegate Class를 상속받을 수 있도록 함 :
     ㄱ. UIAlertViewDelegate, UIActionSheetDelegate ; 
  2)  버튼 클릭시 호출되는 함수를 구현
     ㄱ. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
     ㄴ. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

   
5. 구현소스
...
@interface AlertManagerViewController : UIViewController <UIAlertViewDelegate, UIActionSheetDelegate> {
}

- (IBAction) clickSimple;
- (IBAction) clickMulti;
- (IBAction) clickActionSheet;

...

..
- (IBAction) clickSimple
{
UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"질문에 답해주세요."  
message:@"아이폰 프로그래밍 너무 재미있죠?"  delegate:self 
cancelButtonTitle:@"뭐,그런걸 다" otherButtonTitles:@"당근이죠",nil];
 
[alert show];
[alert release]; 
}

- (IBAction) clickMulti
{
 UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"솔직하게 답해주세요"
message:@"계속 아이폰 프로그래밍 공부 하실 건가요?" delegate:self
cancelButtonTitle:@"말할수 없음" otherButtonTitles:@"당근빳따",
@"기회가된다면!",@"싫어욧!",nil];
 
[alert show];
[alert release];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(alertView.title);
NSLog(@"Pressed button index : %ith", buttonIndex);
 
if(buttonIndex ==2 || buttonIndex ==3)
{
[self clickMulti];
}
}

- (IBAction) clickActionSheet
{
 UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"당신의 열정을 보여주세요" delegate:self cancelButtonTitle:@"뭐 이런걸 다 ..." destructiveButtonTitle:@"나의 열정은 마르지 않는 샘물" otherButtonTitles:@"안개속에서 나는 울었어~",@"외로워서 한참을 울었어~", nil];
 
[actionSheet showInView:[self view]];
[actionSheet release];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(actionSheet.title);
NSLog(@"Pressed button index : %ith", buttonIndex);
 
if(buttonIndex ==2 || buttonIndex ==3)
{
[self clickActionSheet];
}
}
..

6. 실행화면  
  1) clickSimple 실행화면

  2) clickMulti 실행화면

  3) clickActionSheet 실행화면


[특이사항]
1. UIAlertView의 버튼이 2개까지는 옆으로 정렬되어 나오고, 3개 이상부터는 수직으로 펼쳐진다.
2. 버튼 클릭시 발생하는 clickedButtonAtIndex 함수에서 인자로 넘어오는 buttonIndex 값이 UIAlertView와 UIActionSheet의 기준이 틀림
   1) UIAlertView : Canel 버튼이 항상 0이고, 나머지 버튼들이 순차적인 index를 지님
   2) UIActionSheet : Canel 버튼을 포함하여, 위에서부터 순차적인 index를 지님
3. 여러개의 Alert이나 ActionSheet가 있을 경우, title값을 확인하여 어쩐 질문인지를 파악할 수 있음.
   ( 스트링 비교가 부담될 것 같은데, 더좋은 방법이 있을까? : 물론 생성하는 alertView의 포인터를 관리하는 방법이 있겠으나 일반적으로 사용하는 방법은? )
 

Posted by 꿈을펼쳐라
,


1. Project 생성
  1) Create a new Xcode Project -> View based Application -> "PickerTest"

2. Picker View 추가/연결하기
  1) PickerTestViewController.xib 실행
  2) Library 창에서 "Picker View"와 "Label"을 윈도우로 Drag & Drop 
  3) IBOutlet 변수 추가
@interface PickerTestViewController: UIViewController {
IBOutlet UIPickerView *dataPicker;
IBOutlet UILabel *selectedText;

}
@end

  4) File's Owner 선택해 "Picker View"와 "Label"에 각각 변수연결
  5) UIPickerViewDataSource 클래스의 " required" 메소스 추가
    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView 
      Picker Control의 Picker 갯수 (선택 항목 갯수)
    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 
      Picker Control의 항목갯수 (행 갯수)
  6) UIPickerViewDelegate 클래스의 " required" 메소스 추가
   - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)
component 
      Picker Control의 각 항목의 내용 입력     
  7) 헤더 파일에, <UIPickerViewDataSource,UIPickerViewDelegate> 에서 상속됨을 표시
  8) View 화면에서 "Picker View"를 File's Owner로 Drag & Drop하여, dataSource와 delegate를 연결

3. 출력 데이터를 적용
 1) 헤더파일 멤버변수 추가
    - NSMutableArray *pickData; 추가
 2) 배열 초기값 입력 
   - (void)viewDidLoad 함수에서 pickData 
   - NSMutableArray 초기화 방법 적용
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  pickData = [[NSMutableArray alloc]init];
 [pickData addObject:@"1등입니다."];
 [pickData addObject:@"2등입니다."];
 [pickData addObject:@"3등입니다."];
 [pickData addObject:@"4등입니다."];
 [pickData addObject:@"5등입니다."];
 [pickData addObject:@"6등입니다."];
 [pickData addObject:@"7등입니다."];
 3) 선택된 항목을 Label에 출력하기 
  - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
  //NSLog(@"value : %i", row);
 selectedText.text = [pickData objectAtIndex:row];
}

4. Source 및 해더 파일

@interface PickerTestViewController: UIViewController {
IBOutlet UIPickerView *dataPicker;
IBOutlet UILabel *selectedText;

NSMutableArray *pickData;

}
@end


...
 
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
pickData = [[NSMutableArray alloc]init];
[pickData addObject:@"1등입니다."];
[pickData addObject:@"2등입니다."];
[pickData addObject:@"3등입니다."];
[pickData addObject:@"4등입니다."];
[pickData addObject:@"5등입니다."];
[pickData addObject:@"6등입니다."];
[pickData addObject:@"7등입니다."];

 
[super viewDidLoad];
}

...

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [pickData count];
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return [pickData objectAtIndex:row];
// return @"피커뷰 입니다.";
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
NSLog(@"value:%i",row);
selectedText.text = [pickData objectAtIndex:row];
}


- (void)dealloc {
[pickData release]; 
[dataPickerrelease]; 
[selectedText release]; 


[super dealloc];
}

...

 

TRACE 적용하기

Source 중에 NSLog(@"value:%i",row); 와 같이 출력하고자 하는 Text를 문법에 맞춰 코딩하고, 실행시 Xcode의 gdb버튼을 클릭하면, 해당 소스가 실행될때, gdb 실행윈도우에 문법에 해당하는 Text가 출력됨.


[Question]
pickData 이넘을 release 해주는 것인 맞는 것인가요?
Posted by 꿈을펼쳐라
,


1. Project 생성
  1) Create a new Xcode Project -> Window based Application -> "SendData"

2. Navigation Controller 추가/구현
  1) Navigation Controller 추가 (Drag & Drop)
  2) Header /Source 파일에 변수 및 addSubView 함수 추가
  3) 변수 연결

3. 클래수 추가 
  1) 세개의 뷰를 추가 
     a. Class 폴더 마우스 우측 클릭, Add -> New File -> "UIView Controller subClass" with Xib for user interface
         "FirstView", "SecondView" 추가
     b. "Text Field" "Round Button"을 first view에 Drag & Drop 추가 
     c. header 관련 변수 및 함수 추가
@interface FirstView : UIViewController {
IBOutlet UITextField *textData;
}
-(IBAction) sendSecondView;
@end

    d. 변수와 함수를 연결 (FirstView.Xib )
      - 변수 연결 : File's Owner는 먼저 선택하고 마우스 오른쪽 클릭 후 Text Field에 Drag & Drop 후 "textField" 선택
      - 함수 연결 : Round Button을 먼저 선택하고 File's Owner에 Drag & Drop 후 "sendSecondView" 선택
    e. Navigation Cotroller에 FirstView 적용 
      - MianWindow.Xib에서 Navigation Controller를 펼쳐, View Controller를 선택
      - View Controller의 Attributes창(Cmmnd+1)에서 NIB NAME에서 FirstView를 선택, Identity에서도 Class 항목을 FirstView Class를 선택하여 실행  
     f. 함수 연결 및 추가
#import "FirstView.h"
#import "SecondView.h"

@implementation FirstView

...

-(IBAction) sendSecondView
{
UINavigationController *sNav = self.navigationController;
 
SecondView *sView = [[SecondView alloc] initWithNibName:@"SecondView"     bundle:nil];
 
[sNav pushViewController:sView animated:YES];
[sView release]; 
}

...

- (void)dealloc {
[textField release];    
[super dealloc];
}

4. XIB 연동 및 값전달
  1) SecondView 구현 
     a. NSString *recevieData 변수 추가 및 @property 및 @synthesize 구현
     b. View에 Label Drag & Drop하고 변수추가(IBOutlet UILabel *lblText) 및 연결
@interface SecondView : UIViewController {
NSString *receiveData;
IBOutlet UILabel *lblText;

}
@property (readwrite, assign) NSString *receiveData;
@end
@implementation SecondView
@synthesize receiveData;

...
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
lblText.text = receiveData;
[super viewDidLoad];
}

...

- (void)dealloc {
[lblText release];
[super dealloc];
}

  2) FirstView의 sendSecondView에 값전달 기능 구현
-(IBAction) sendSecondView
{
UINavigationController *sNav = self.navigationController;
 
SecondView *sView = [[SecondView alloc] initWithNibName:@"SecondView"     bundle:nil];
sView.receiveData = textData.text; 
 
[sNav pushViewController:sView animated:YES];
[sView release];

 }
Posted by 꿈을펼쳐라
,




1. Project 생성
  1) Create a new Xcode Project -> Window based Application -> "TabBarNavi"

2. Tabbar 구현
  1) Interface Builder 실행(Mainwindow.xib 더블클릭) -> Library 창실행 (shift + Cmmnd + L ) ->Tab Bar Controller를 MainWindow.xib 윈도우로 Drag & Drop
  2) Tab Bar Controller 연동하기
    a. header 파일에 IBOutlet UITabBarController *mainTab; 선언
    b. source 파일에서 [window addSubview:mainTab.view]; 와 해제시 [mainTab release];를 선언함.
    c. MainWindow.xib 화면에서 App Delegate와 Tab Bar Controller의 mainTab을 연결함
  3) Tab Bar Controller 설정 
    a. MainWindow.xib 화면에서 Tab Bar Controller 선택 후 Attributes 창 실행 (Cmmnd +1)
    b. View Controllers 항목의 Title을 변경하고(첫번째, 두번째), Class 항목을 View Controller를 Navigation Controller로 변경함.
    c. "+" 버튼을 눌러, "세번째" Navigation Controller를 추가함. 
    d. 배경이 투명한 이미지를 활용하여 Tab 이미지 추가
      - resource 폴더에서 세개의 이미지 추가
      - MainWindow.xib 화면에서 Tab Bar Controller Tree 구조를 확장시킨 후, 각 Tab Bar Item의 Atrributes 윈도우에서 "Image"항목에서 해당하는 이미지를 지정함 

4. 뷰구현
  1) 세개의 뷰를 추가 
     a. Class 폴더 마우스 우측 클릭, Add -> New File -> "UIView Controller subClass" with Xib for user interface
         "FirstViewList", "SecondView", "ThirdView" 추가
  2) FirstViewList 에 Table View 연결
     a. FirstViewList.Xib를 열고, 라이브러이에서 "Table View"를 Drag  Drop한다.
     b. Table View 를 선택하고, FirstViewList의 File's Owner에 드래그해서, datasource와 delegate를 연결한다. 
     c. FirstViewList의 source파일에 table view의 필수함수 구현 (FirstViewList.m)
...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *kIdentifier = @"cell";
 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kIdentifier];
 
if(cell == nil)
{
  cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kIdentifier] autorelease];
}
 
cell.textLabel.text = @"첫번째 뷰 리스트 입니다.";
 
return cell;
 }

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 return 5;
}

...


continue ....





  3) View Controller Xib 연결하기
    a. Tab Bar Controller를 펼쳐 각 탭에 해당하는 View Controller를 선택하여 Attribute창(Cmmnd+1)에서 각각 해당하는 Xib를 설정하고, Identity창(Cmmnd+4)에서 Class를 신규로 추가한 클래스를 각각 지정한다. 

  4) Xib title 변경하기
-(id) initWithCoder:(NSCoder *)aDecoder
{
if(self =[ super initWithCoder:aDecoder])
{
self.title = @"첫번째 ^^";
}
 
return self;
}
 
5. Navigation 구현하기
  1) Detail 뷰추가 
    a. Class 폴더 마우스 우측 클릭, Add -> New File -> "UIView Controller subClass" with Xib for user interface
         "FirstViewDetail" 추가
    b. Label 객체 " 디테일 뷰 입니다." 추가
  2) 첫번째 테이블 화면에서, 각 셀 클릭시 디테일 뷰로 전환
...

#import "FirstViewDetail.h"

...

(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UINavigationController *naviCtrl = self.navigationController;
 
FirstViewDetail  *FViewDetail= [[FirstViewDetail alloc]initWithNibName:@"FirstViewDetail"  bundle:nil];
 
[naviCtrl pushViewController:FViewDetail animated:YES]; 
}

  3) 두번째, 세번째 뷰에서 라벨 추가
   
Posted by 꿈을펼쳐라
,



1. 프로젝트 생성 
  1) Xcode - Create a new Xcode Project - Window Based Project - "MultiXib"
  2) "Navigation Controller" 추가
  3) Navigation Controller 관련 소스 추가
@interface MultiXibAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
IBOutlet UINavigationController *naviCtrl;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
// Override point for customization after application launch
[window addSubview:naviCtrl.view];
[window makeKeyAndVisible];
return YES;
}

- (void)dealloc {
[naviCtrl release];
[window release];
[super dealloc];
}
2. Xilb 파일 생성
 1) class 항목에서 마우스 우클릭 -> Add -> New File ...  ( 혹은 메뉴에서 File -> New File ...) 실행
 2) iPhone OS 항목중 Cocoa Touch Class를 선택하고, UIViewController 선택.
 3) option항목중 "With XIB for user interface"를 선택. Next
 4) 클래스 이름을 입력함 ( mainView, firstView, secondView 추가)


3. mainView MainWindow에 나타내기
  1) mainView.xib를 선택, view에 구분가능한 라벨 추가
  2) MainWindow.xib에서 "Navigation Controller"를 선택하고 Atrribute(Cmmnd + 1)창을 띄움 
  3) NIB 입력항목에 구현하고자 하는 .xib를 하나 선택함 (Main View













































4. TaleView 및 Navigation 기능 구현
 1) mainView에 TableView를 드럽하고, File owner's와 DataSource, Dellegate를 연결
 2) mainView.m 파일에 Table View의 필수 함수를 구현 
 3) 셀을 클릭했을 때, 각가의 xib와 연결하여는 기능


#import "MainXib.h"
#import "FirstXib.h"
#import "SecondXib.h"

@implementation MainXib


/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
   
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(int)section
{
 return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
 static NSString *kIdentifier
=@"cell";
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kIdentifier];
 
 if(cell == nil){
  cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kIdentifier] autorelease];
 }
 
 if(indexPath.row==0)
 {
    cell.textLabel.text = @"첫번째 항목입니다.";
 }
 else
 {
  
  cell.textLabel.text = @"두번째 항목입니다.";
 }
   return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
 UINavigationController *mainNavCon = self.navigationController;
 if(indexPath.row==0)
 {
  
  FirstXib *firstView = [[FirstXib alloc]initWithNibName:@"FirstXib" bundle:nil];
  [mainNavCon pushViewController:firstView animated:YES];
 }
 else
 {
  SecondXib *secondView = [[SecondXib alloc]initWithNibName:@"SecondXib" bundle:nil];
  [mainNavCon pushViewController:secondView animated:YES];
 }
}

- (void)dealloc {
    [super dealloc];
Posted by 꿈을펼쳐라
,



1. Project 생성하기
  1) Create a new Xcode Project -> Window-Base Application -> "NaviTest"

2. Navigation Control 구현하기
  1) IB 실행시킨 상태에서 Library창에서 Navigation Controller를 MainWindow.xib 창으로 Drag&Drop
  2) 헤더 파일에 해당변수 선언 / View 적용, 소스파일에서 해제 
@interface NaviTestAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window; 
IBOutlet UINavigationController *mainNav;
 }

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
// Override point for customization after application launch
[window addSubview:mainNav.view];
[window makeKeyAndVisible];
return YES;
}

- (void)dealloc {
//IBOutlet으로 선언한 변수는 반드시 해제해야함
[mainNav release];
[window release];
[super dealloc];
}
(## 향후 소스코드 내용은 포함은 헤더파일은 연두색, 소스파일은 하늘색으로 표현할 예정임)
  3)  MainWindow.xib에서 "Navi Test App Delegate"를 Drag&Drop으로 Navigation Controller에 한후, 헤더에서 선언한 mainNav를 선택함 ( Drag & Drop 방향 중요 : 반대방향으로 하면 다른 팝업이 뜸)

3. View 추가하기
  1) Library 창에서 "View Controller"를 선택해서 MainWindow.xib로 Drag & Drop하여 3개를 만들고, 각 View Controller의 Title을 "root/first/second:ViewController"로 설정한다. (Attributes 창에서 : Cmmnd + 1)
  2) View Controller에서 다른 Control이나 Object를 바로 올리면 안되고, Cocoa Touch에서 "View"를 Drag & Drop해서 화면을 덮어줘야 가능함.
  3) 각 뷰에 적당한 Label을 입력
  4) Source 추가
@interface NaviTestAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window; 
IBOutlet UINavigationController *mainNav;
IBOutlet UIViewController *rootView;
IBOutlet UIViewController *firstView;
IBOutlet UIViewController *secondView;

// 위를 이렇게 선언해도 문제는 없음  <---
// IBOutlet UIViewController *rootView, *firstView, *secondView;
// --->

 }

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
mainNav.viewControllers =[NSArray arrayWithObject:rootView];
 rootView.title =@"나는 루트뷰입니다.";
// Override point for customization after application launch
[window addSubview:mainNav.view];
[window makeKeyAndVisible];
return YES;
}

- (void)dealloc {
//IBOutlet으로 선언한 변수는 반드시 해제해야함
[rootView release];
[firstView release];
[secondView release];

[mainNav release];
[window release];
[super dealloc];
}
(## 향후 소스코드 내용은 포함은 헤더파일은 연두색, 소스파일은 하늘색으로 표현할 예정임)
  5) Delegate 연결 : MainWindow.xib의 "Navi Test App Delegate"를 각 View Controller에 Drag & Drop한 후 해당하는 변수에 연결한다.

4. 화면전환 네비게이션 구현하기
  1) rootView의 Label을 지우고, "table view"를 rootView window에 올려놓는다.
  2) "table view"를 사용할 때는 기계적으로 App Delegate와 dataSource/Delegate를 연동한다.
  3) table view의 require function을 추가
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *kIdentifier = @"cell";
 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kIdentifier];
 
if(cell ==nil)
{
  cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kIdentifier];
}
 
if (indexPath.row ==0) {
cell.textLabel.text = @"첫번째 행입니다.";
 }
 else {
cell.textLabel.text =@"두번째 행입니다.";
 }
 
 return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 return 2;
}

   4) firstView, SecondView 도 rootView와 마찬가지로  윈도우 위에 View를 덮고, 식별할 수 있는 라벨을 추가한다. 
   5) UITableViewDelegate의 도움말을 확인하여 필요한 함수 검색 ( 셀 마우스 클릭시 동작 이벤트 처리)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
 if(indexPath.row ==0)
 {
  [mainNav pushViewController:firstView animated:YES];
 }
 else
 {
  [mainNav pushViewController:secondView animated:YES];
 }
}

 

Posted by 꿈을펼쳐라
,


  [강의 내용]
  1. Main Window 이외의 추가적으로 윈도우 생성 / 전환 / 삭제
  2. Window-Based Project


1.Project 생성하기
  1) Create a Xcode Project -> Window-based Application - > "ChangeView"
  2) Interface Builder 실행 -> Library (Shift + Cmmnd + L ) -> "View" ( Cocoa Touch) 2개를 MainWodw.xib 추가

2. View와 Xcode 연결 
  1) ChangeViewAppDelegate.h 파일에 view 관련 변수 추가
@interface ChangeViewAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
 
 IBOutlet UIView *firstView;
 IBOutlet UIView *secondView;

}

  2) Interface Builder와 변수 연결하기 
      a. MainWindow.xib 파일 내에 "Change View App Delegate" 항목을 선택한 후 마우스우클릭 ( 혹은 Cmmnd키를 누르고 마우스 좌클릭)을 통한 Drag&Drop으로 view 항목에 연결  
  3) view 변경
      a. MainWindow.xib에서 view를 선택하고 Identity("Cmmnd + 4") 창을 열어, Name 항목에 해당하는 명칭을 입력 
      b. Label 추가 : 명칭 입력 / 버튼 추가 : 명칭 추가 ( firstView, ㄴecondView 모두)  
  4) 생성된 뷰를 MainWindow에 반영하기 
      a. ChangeViewAppDelegate.m 파일,  didFinishLaunchingWithOptions함수에 첫번째 뷰 추가
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
// Override point for customization after application launch
[window addSubview:firstView];
[window makeKeyAndVisible];
 return YES;
}
  4) 뷰전환 기능 구현
      a. 함수선언 : ChangeViewAppDelegate.h 에 추가
-(IBAction) ChangeView;
      b. Delegate 연결 : firstView, secondView에 생성한 Button을 우클릭하여 MainWindow.xib의 "Change View App Delegate"에 Drag&Drop한 후 ChangeView 함수를 선택한다.  
      c. ChagneView 함수 내용 구현
-(IBAction) ChangeView
{
NSArray *subs = [window subviews];
 
//window 객체는 하나의 view를 가짐
[[subs objectAtIndex:0]removeFromSuperview];
 
if([subs objectAtIndex:0]== secondView)
{
[window addSubview:firstView];
}
else {
[window addSubview:secondView];
}
}

[질문] firstView, secondView는 alloc를 하지 않는가? 
  - (자답) 이미 Interface Builder를 통해 생성되어 있고, 마우스 우클릭 과정을 통해 각변수의 포인터로 연결시켰음. 

[질문] firstView, secondView를 Pointer 형이 아닌 UIView 변수로도 받을 수 있을까? 
  - 몰라, 해 봐봐..  -> 해봤는데, xib에서 Drag&Drop 기능도 안되고 컴파일시에도 헤더파일 선언부에서 에러가 발생하는 것으로 보아 무조건 포인터 형으로 받아야 됨.
 
Posted by 꿈을펼쳐라
,

1. 프로젝트 생성하기 
  1) Create a Xcode Project :View-based Project - "TableViewControl"  
      => 이름이 너무 길어, 나중 아이폰 실행화면에서, 아이폰 밑의 실행화일 명칭이 축소 생략되어 나타남. 
          ( 프로젝트 생성시 향후 실행화일 명을 고려해서, 적당한 길이로 명명)
  2) TableViewControlViewController.xib 더블클릭 Interface Builder 실행
  3) Library[Cmmnd + Shift + L ] 실행
    a. Object - Library - Cocoa Touch - Data Views - Table View 선택( Table View Controller 가 아님.) 
    b. "Table View"를 TableViewViewControler.xib의 View 화면 위로 Drag& Drop : 위치 약간 조절
  4) Inspector [Cmmnd + Shift + I] 실행 ( Table View 가 선택된 상태에서 실행)
    a. Identity tab : 
       - Style : plain / group  
       - Separator : None, Single Line, Single Line Etched (엷게 드러내다 : pain 뷰에서는 지원되지 않음)  
       # 해당위치에 마무스를 고정시켜 놓으면 각 항목에 해당하는 풍선도움말이 나타남.
  5) 아웃렛 연결하기
     a. View에 있는 "Table View"를 선택 (화면 반전, 잘 안 될경우, Title Bar "View" 부분 클릭후 재시도)
     b. 선택한 상태에서 "Ctrl"을 누른 상태에서, File's Owner에 -datasource, -delegate에 연결
         (마우스 오른쪽 클릭 후 Drag해도 동일 효과) 
       - datasource / delegate 두개는 protocol로 IB를 사용하지 않는다면 하나하나 코딩을 추가해야 한다.
       - datasource : table에 표현되는 data의 속성 설정
       - delegate : table 자체 속성을 설정
  6) 필수 함수 구현하기 
     a. source 파일을 선택 (*.h, *.m) 
     b. 메뉴 : Help - Developer Documentation 
     c. UITableViewDataSource 입력   : 
        Tasks - Configuring a Table View 항목에서 "required method"라는 항목을 확인 할 수 있음. 
     d. 위 "c"항목의 두개 함수 원형을 도움말에서 복사해서, "TableViewControlViewController.m" 파일에
       함수 형태로 추가   

// Table Cell 갯수
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
// indexPath에 해당하는 셀 생성
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
 static NSString *cIdentifier = @"cell";
 
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cIdentifier];
 
 if(cell ==nil)
 {
   cell = [[[UITableViewCell alloc]
      initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cIdentifier]autorelease];
 }
 
 cell.textLabel.text = @"아이폰 개발은 정말 재미있어~ "; 
 return cell;

}



2. 각 셀 항목에 특정 Data의 내용이 나타나도록 구현
  1) NSArray에 임의의 Text를 넣고, 각셀에 해당 내용이 출력되는 기능 구현
  2) 클래스 멤버 변수로 활용하기
    a. "TableViewControlViewController.h " 파일에  TableViewControlViewController클래스 내부에 선언
@interface TableControlViewController : UIViewController {
 NSArray *listData;
}

//Object-C에서 해당값을 사용하기 위한 get, set 관련 내용은 메크로 처리인듯함.( 확인필요)
@property (nonatomic, retain) NSArray *listData;
     b. "TableViewControlViewController.m" 파일에 다음의 내용 추가
#import "TableControlViewController.h"

@implementation TableControlViewController

// 뭐 헤더에서 선언한 listData를 동기화 해서 사용하겠단 그런 이야기 겠지.
@synthesize listData;
  3) 해당변수배열(listData)에 초기값 넣기
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
// NSArray 입력값의 맨 마지막이 "nil"임을 확인하자!
listData = [NSArray arrayWithObjects:@"SimVerse = Sim(ulate) + (Uni)Verse", @"세상을 시뮬레이션 하자", @"너무 허황되다구? ",@"난 가능하다고 생각해", @"힌트는 SNS 야", @"미래는 꿈 꾸는 자의 것이 아니라, 실천하는 자의 것이다.",nil];
[super viewDidLoad];
}
  4) 추가한 함수에 해당 내용 반영하기 및 메모리 삭제하기
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 return [listData count]  ;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
 static NSString *cIdentifier = @"cell";
 
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cIdentifier];
 
 if(cell ==nil)
 {
   cell = [[[UITableViewCell alloc]
      initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cIdentifier]autorelease];
 }
 
 cell.textLabel.text = [listData objectAtIndex:indexPath.row];
 
 return cell;

 
}

- (void)dealloc {
[listData release];
[super dealloc];
}



[질문] 어떤때는 return [listData count]와 같이 [ ]의 용도는?   (음.. 역시 Object-C도 빨랑 시작해야 겠군)
Posted by 꿈을펼쳐라
,