2014-04-17 2 views
0

정수를 사용하여 다음 뷰로 전달하는 간단한 코드가 있지만 다른 뷰에서는 int가 항상 0으로 끝납니다. 변수에 문제가 없다는 것을 알기 때문에 메인 뷰에서 실제 int로 밝혀졌습니다.뷰 간 int 전달이 작동하지 않습니다.

AnswerViewController *ansViewController = [[AnswerViewController alloc] initWithNibName:@"AnswerViewController" bundle:nil]; 
ansViewController.num = theNum; 
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
UIViewController *mainView = [storyBoard instantiateViewControllerWithIdentifier:@"ansView"]; 
[self presentViewController:mainView animated:YES completion:nil]; 

답변

1

여기에 올바른 방법입니다 : 여기 내 코드는

//Initialize the storyboard 
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
//initialize the ViewController 
AnswerViewController *ansViewController = 
    [storyBoard instantiateViewControllerWithIdentifier:@"AnswerViewController"]; 
//Assign the value to the controller property 
ansViewController.num = theNum; 
//Finally present the view Controller 
[self presentViewController:ansViewController animated:YES completion:nil]; 
+0

ansViewController를 선언, 대신 스토리 보드 스토리 보드를 찾으시는 것입니까? 또한 mainview를 선언하지 않았습니다. – lagoon

+0

죄송합니다. 오타였습니다. 수정했습니다. – meda

+0

감사합니다. 그러나 현재의 presentViewController는 mainView가 정의되지 않았습니다. – lagoon

관련 문제