2011-01-08 2 views
1

하나의 viewcontroller에서 다른 viewcontroller로 전환하는 데 문제가 있습니다. 내 "AppDelegate_iPad.m"에서한 UIViewController에서 다른 UIViewController로 전환하는 방법은 무엇입니까?

: 작동

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{  

    CGRect frame = [UIScreen mainScreen].bounds; 
    window = [[UIWindow alloc] initWithFrame:frame]; 
    window.backgroundColor = [UIColor blackColor]; 

    LoginViewController_iPad *loginView = [[LoginViewController_iPad alloc] initWithNibName:@"LoginViewController_iPad" bundle:nil]; 
    [window addSubview:loginView.view]; 


    [self.window makeKeyAndVisible]; 

    return YES; 
} 

을 여기

내가 가진 것입니다. 이제 해당 화면에 로그인 버튼이 있는데 이것을 누르면 다음과 같이 호출됩니다.

- (IBAction)doPressLoginButton 
{ 
    DebugLog(@"doPressLoginButton"); 

    MenuViewController_iPad *menuView = [[MenuViewController_iPad alloc] initWithNibName:@"MenuViewController_iPad" bundle:nil]; 
    [self.navigationController pushViewController:menuView animated:YES]; 
    [menuView release]; 

} 

문제는 발생하지 않습니다. 나는 실제 navigationconroller가없는 것 같아요?!

누구든지 도움을 주시기 바랍니다.

내가 실제 navigationconroller을 잃었 가정

답변

1

응용 프로그램 대리인에 UINavigationController 인스턴스 변수를 만들어야합니다. 그런 다음 합성하고 dealloc 메소드에서 해제해야합니다.

application:didFinishLaunchingWithOptions:의 구현은 다음과 같이 수 :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{  

    // window is usually an IBOutlet 
    CGRect frame = [UIScreen mainScreen].bounds; 
    window = [[UIWindow alloc] initWithFrame:frame]; 
    window.backgroundColor = [UIColor blackColor]; 

    LoginViewController_iPad *loginView = [[LoginViewController_iPad alloc] initWithNibName:@"LoginViewController_iPad" bundle:nil]; 
    navigationController = [[UINavigationController alloc] initWithRootViewController:loginView]; 
    [loginView release]; 

    [self.window addSubview:navigationController.view]; 
    [self.window makeKeyAndVisible]; 

    return YES; 
}

이제 self.navigationController를 사용할 수 있습니다.

+0

IBOutlet 인 창에 대한 귀하의 의견과 관련하여. 글쎄, 나는 MainWindow.xib없이 작업한다는 것을 알기 때문에 직접 윈도우를 생성한다. – eemceebee

0

감사합니다?!

당신 말이 맞습니다. : D

self.navigationController은 NavigationController를 설정하지 않으면 nil을 반환합니다.
nil 개체로 보내는 메시지는 무시됩니다.

하나만 전환하면됩니다. 사용

[self presentModalViewController:modalViewController animated:YES]; 

대신에.

+0

전환 할 수는 있지만 presentModalViewController가 오류를 throw합니다. 구조체 또는 공용체가 아닌 무언가에 'presentModalViewController'멤버를 요청하십시오. – eemceebee

관련 문제