2011. 12. 5. 10:51

[Xcode 4.2] 스토리보드를 이용한 객체 생성

기존의 xib을 이용한 객체생성은 아래와 같았다.

RootViewController *rootViewController = [[RootViewController alloc] initWithNibName:@"NIB명" bundle:nil];

하지만 4.2부터 스토리보드를 이용할 경우 xib파일이 없기 때문에 위의 방법은 쓸 수 없다.

스토리보드를 이용한 방법은 아래와 같다.

RootViewController *rootViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"identifier"]];

identifier자리에는 스토리보드에서 설정한 view controller의 identifier를 적어주면 된다.

또한 뷰 전환은 아래와 같이 하면 된다.

[모달]
[self presentModalViewController:rootViewController animated:YES];

[푸쉬]
[self.navigationController pushViewController:rootViewController animated:YES];