'Xib'에 해당되는 글 1건

  1. 2010.06.18 [AppsNext] iPhone SDK 기본강좌_8강 Xib 파일간 값 전달


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 꿈을펼쳐라
,