2013-06-17 3 views
2

하나의 응용 프로그램을 만들고 양식 제출을 포함하고 싶습니다. 이 단일 뷰 응용 프로그램에서 하나의 새 프로젝트를 만듭니다. 이 firstViewController에 button을 두었고 그것을 누르면 secondViewController로 리디렉션됩니다.하나의보기 컨트롤러에서 xib 파일을 통해 다른보기 컨트롤러에 데이터 전달

이 형식이 있습니다. 그리고 사용자로부터 데이터를 가져오고 버튼을 제출하여 이것을 thirdViewController로 리디렉션하고 thirdViewController에서 양식 데이터를 인쇄하려고합니다.

가 firstViewController.m 파일에서 내가 쓴

-(IBAction)nextVCButton:(id)sender 
{ 

SecondViewController *tempView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 

NSLog(@"name : %@",self.nameTextField.text); 
tempView.fullName = self.nameTextField.text; 
[tempView setFullName:self.fullName]; 
[self.view addSubview:tempView.view]; 

}

SecondViewController.m에서받은 난 (점점 이름 : 값 만 secondViewController에 있어요 로그에서

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view from its nib. 

NSLog(@"received info %@", [self.fullName description]); 

self.nameLabel.text = [self.fullName description]; 

} 

파일 정보가 null입니다.

저는 xib 파일을 사용하여이 모든 작업을 수행하고 있습니다. 스토리 보드를 사용하지 않습니다.

이 양식 데이터를 secondViewController로 가져 오는 것을 도와주십시오.

감사합니다.

tempView.fullName = self.nameTextField.text; 
[tempView setFullName:self.fullName]; 

는 대신, 이 두 번째보기 컨트롤러의 .h file

@property (nonatomic,retain) NSString *strFullName; 

NSString의 속성을 확인하고의 합성 :이 두 라인의 코드를 할 이유

+0

두 번째 뷰 컨트롤러를로드 addsubview를 사용하고 계십니까? 심각? 그럼 왜 UINavigationController' 클래스는 만들어지는'? –

+0

http : // stackoverflow.co.kr/questions/5210535/passing-data-between-view-controllers –

+0

버튼을 사용하여 하나의보기를 다른보기로 이동하고 해당 컨트롤러에서 다시 단추를 통해 세 번째 컨트롤러로 이동하는 것이 더 좋습니다. – Zeel

답변

2

죄송합니다, 나는 가져올 수 없습니다 .m file. 이제

@synthesize strFullName; 

,

-(IBAction)nextVCButton:(id)sender 
{ 

SecondViewController *tempView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 

NSLog(@"name : %@",self.nameTextField.text); 
tempView.strFullName = self.nameTextField.text; 
[self.view addSubview:tempView.view]; 
} 
+0

정말 고마워. 나는 이미 같은 일을했지만이 줄 때문에 [tempView setFullName : self.fullName]; 나는 널 얻고있다. 이제 이것을 제거한 후 잘 작동합니다. 나는 이것을 위해 2 일을 보낸다. 귀중한 답변에 감사드립니다. – Zeel

+0

환영합니다. 해피 코딩 (: –

+0

단추로 다른보기를 다른보기로 이동하고 해당 컨트롤러에서 다시 한 번 단추를 통해 세 번째 컨트롤러로 이동하는 것이 더 편합니다. – Zeel

1

나는 당신이 다른 뷰 컨트롤러에 하나의 뷰 컨트롤러에서 이동하려면 Navigation controller을 사용할 필요가 있다고 생각합니다. 여기에서 속성을 수행해야합니다 - ThirdViewController에서 iVar "fullName"을 합성하십시오. 값은 SecondViewController으로 유지하십시오.

1 ThirdViewController.h

@property(nonatomic, retain) NSString *fullName; 

2 ThirdViewController.m

@synthisize fullName; 
dealloc { 
[fullName release]; 
} 

3. SecondViewController.m

-(IBAction)nextVCButton:(id)sender 
{ 

SecondViewController *tempView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 

NSLog(@"name : %@",self.nameTextField.text); 
tempView.fullName = self.nameTextField.text; 
[tempView setFullName:self.fullName]; 
[self.view addSubview:tempView.view]; 
} 
+0

답안 형식을 사용하십시오 ... 여러분과 독자에게 좋은 .. –

+0

그래, 고마워 "Nitin Gohel" – kulss

0

대신 addSubview의 presentViewController 방법 .... 시도

-(IBAction)nextVCButton:(id)sender 
{ 
    SecondViewController *tempView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 

    NSLog(@"name : %@",self.nameTextField.text); 
    tempView.strFullName = self.nameTextField.text; 
    [self.view addSubview:tempView.view]; 
    [self presentViewController:tempView animated:YES completion:nil]; 
} 
관련 문제