2012-01-11 7 views
0

처음 응용 프로그램을 시작할 때 페이지를 표시하는 방법을 알고 싶습니다.이 코드를 가져 와서 많은 코드를 얻을 수 있지만 제 경우에는 작동하지 않습니다. DidFinishLaunching 메서드에서이 코드를 사용합니다.처음 응용 프로그램 시작시 UIViewController를 표시하는 방법?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],@"firstLaunch",nil]]; 

    //If First Launch 
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) { 
     //Show help view 
     UIScrollView_PagingViewController *detailViewController = [[UIScrollView_PagingViewController alloc] initWithNibName:@"UIScrollView_PagingViewController" bundle:nil]; 

     //detailViewController.firstString = firstString; 
     // ... 
     // Pass the selected object to the new view controller. 

     [self.navigationController pushViewController:detailViewController animated:YES]; 

     [detailViewController release]; 

    } 
    else { 
    NSError *error = nil; 
    NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:@"username"]; 
    NSString *str = [SFHFKeychainUtils getPasswordForUsername:username andServiceName:@"mybibleapp" error:&error]; 
    NSLog(@"previous user"); 

    NSLog(@"%@", str); 

    if (!error && nil != str) 
    { 
     ParallelReadViewController *detailViewController = [[ParallelReadViewController alloc] initWithNibName:@"ParallelReadViewController" bundle:nil]; 

     //detailViewController.firstString = firstString; 
     // ... 
     // Pass the selected object to the new view controller. 

     [self.navigationController pushViewController:detailViewController animated:YES]; 

     [detailViewController release]; 
    } 
    else 
    { 
     RootViewController *detailViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil]; 

     //detailViewController.firstString = firstString; 
     // ... 
     // Pass the selected object to the new view controller. 

     [self.navigationController pushViewController:detailViewController animated:YES]; 

     [detailViewController release]; 
    } 
} 

하지만이 코드를 실행하면 아무 것도 표시되지 않는 빈 흰색 화면이 표시됩니다.

[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],@"firstLaunch",nil]]; 

     //If First Launch 
     if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) { 
      //Show help view 
      UIScrollView_PagingViewController *detailViewController = [[UIScrollView_PagingViewController alloc] initWithNibName:@"UIScrollView_PagingViewController" bundle:nil]; 

      //detailViewController.firstString = firstString; 
      // ... 
      // Pass the selected object to the new view controller. 

      [self.navigationController pushViewController:detailViewController animated:YES]; 

      [detailViewController release]; 

     } 
     else { 

은 내가 더 고마워 행운을 빌어 내가 위의 code.?.please에서 만든 실수가 좀 도와 없다 나누었다 시작 발사 UIScrollView_PagingViewController에 대해 위의 코드를 삽입. 미리 감사드립니다.

답변

0

코드를 올바른 위치에 두지 마십시오. 이 코드를 AppDelegate에 두지 마십시오. 더 나은 성능을 위해 가능한 한 깨끗하게 appdelegate를 유지하십시오. 스플래시 화면 이후에 전화를 받고 코드가 작동하는지 확인하는 일부 ViewController를 사용하십시오.

0

컨트롤러를 처음으로 밀어 넣으려고하고 있지만 루어에는 컨트롤러가 없습니다. 그래서 창에 먼저 추가해야합니다. 다음 UIViewController 밀어 넣을 수

self.window.rootViewController = detailViewController.view; 

사용하기 전에 viewController 해제하지 마십시오.

0

 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) 
    { 

    UIScrollView_PagingViewController *detailViewController =[[UIScrollView_PagingViewController alloc] initWithNibName:@"UIScrollView_PagingViewController" bundle:nil]; 

        //detailViewController.firstString = firstString; 
        // ... 
        // Pass the selected object to the new view controller. 

    self.navController=[[UINavigationController alloc] initWithRootViewController:detailViewController]; 
    self.window.rootViewController=self.navController; 

       } 
0

그냥, 은 AppDelegate에이 코드는 성능 향상을 위해 가능한 한 깨끗하게 AppDelegate에 유지하려고 trcik을 넣지 마십시오 않습니다보십시오.

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

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

    return YES; 
} 

그리고 당신은 RootViewController 매번 응용 프로그램이 출시를 얻을 것이다 때, 대신 RootViewController에서 확인합니다, 대리자 메서드의 상태를 확인이 코드를 놓습니다.

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:YES]; 
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],@"firstLaunch",nil]]; 

    //If First Launch 
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) { 
     //Show help view 
     UIScrollView_PagingViewController *detailViewController = [[UIScrollView_PagingViewController alloc] initWithNibName:@"UIScrollView_PagingViewController" bundle:nil]; 

     //detailViewController.firstString = firstString; 
     // ... 
     // Pass the selected object to the new view controller. 

     [self.navigationController pushViewController:detailViewController animated:NO]; 

     [detailViewController release]; 

    } 
    else { 
    NSError *error = nil; 
    NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:@"username"]; 
    NSString *str = [SFHFKeychainUtils getPasswordForUsername:username andServiceName:@"mybibleapp" error:&error]; 
    NSLog(@"previous user"); 

    NSLog(@"%@", str); 

    if (!error && nil != str) 
    { 
     ParallelReadViewController *detailViewController = [[ParallelReadViewController alloc] initWithNibName:@"ParallelReadViewController" bundle:nil]; 

     //detailViewController.firstString = firstString; 
     // ... 
     // Pass the selected object to the new view controller. 

     [self.navigationController pushViewController:detailViewController animated:NO]; 

     [detailViewController release]; 
    } 
    else 
    { 
     // RootViewController *detailViewController = [[RootViewController alloc] //initWithNibName:@"RootViewController" bundle:nil]; 

     //detailViewController.firstString = firstString; 
     // ... 
     // Pass the selected object to the new view controller. 

     // [self.navigationController pushViewController:detailViewController //animated:NO]; 

     //[detailViewController release]; 
    } 
} 
관련 문제