2012-07-18 2 views
0

nib 파일이없는 viewcontrolleroneviewcontroller을 푸시하는 방법은 무엇입니까?nib 파일이없는 다른보기 컨트롤러에 하나의보기 컨트롤러를 푸시하는 방법은 무엇입니까?

이것은 현재 내가하고있는 일입니다. 이 UserViewController에 대한 nib 파일은 생각하지 아직 나는 아직도 어떤 도움 initWithNibName:@"UserViewController"

-(IBAction)userProfile:(id)sender { 

    UserViewController *userViewController = [[UserViewController alloc] 
                  initWithNibName:@"UserViewController" bundle:nil]; 
    [self.navigationController pushViewController:userViewController animated:YES ]; 

    [userViewController release]; 

} 

감사를 사용하고 있습니다!

+1

nib 파일이 없으면 nib name을 제공하지 않아야합니다. 다음과 같이 View Controller를 누를 수 있습니다. UserViewController * userViewController = [[UserViewController alloc] init]; 프로그래밍 방식으로 뷰를 만들 수 있습니다. –

답변

2

nib 파일이 없으면 아무 것도 언급하지 마십시오. 코드를 검색 : 당신은 에 UserViewController 및 설정 전역 변수를 -(id)init 방법을 배치 할 수 있습니다

-(IBAction)userProfile:(id)sender { 

UserViewController *userViewController = [[UserViewController alloc] 
                 init]; 
[self.navigationController pushViewController:userViewController animated:YES ]; 

[userViewController release]; 

} 

.

3

당신은 사용

[[UserViewController alloc] init]; 

당신은 loadView 방법에서 해당 뷰를 구축 할 수 있습니다. 그러나 Apple의 View Controller Guide을 확인하십시오.

0
-(IBAction)userProfile:(id)sender { 

UserViewController *userVC = [[UserViewController alloc] init]; 

// Replace the current view controller 
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:[[self navigationController] viewControllers]]; 
[viewControllers removeLastObject]; 
[viewControllers addObject:userVC]; 
[[self navigationController] setViewControllers:viewControllers animated:YES]; 
} 
관련 문제