2012-12-12 3 views
0

장치에서 처음으로 응용 프로그램을 시작할 경우 표시되는 "초기 설정 페이지"를 만들려고합니다. 첫 번째 시작 viewcontroller 만들기

나는 이런 식으로했다 :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 


    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"]) 
    { 
     NSLog(@"not first launch"); 
     self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 
     self.window.rootViewController = self.viewController; 
     [self.window makeKeyAndVisible]; 
     return YES; 

    } 
    else 
    { 
     [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"]; 
     [[NSUserDefaults standardUserDefaults] synchronize]; 



     NSLog(@"first launch"); 

    } 
} 

지금 내가보기 컨트롤러를 만들고 앱이 출시되어 처음 인 경우이 뷰 컨트롤러에 밀어합니다.

무엇을해야합니까?

답변

4

새 ViewController를 만듭니다. appDelegate.h 파일의 헤더를 가져오고 이름이 initialViewController 인 해당 클래스의 인스턴스 변수를 만듭니다.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"]) 
    { 
     NSLog(@"not first launch"); 
     self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 
     self.window.rootViewController = self.viewController; 
    } 
    else 
    { 
     [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"]; 
     [[NSUserDefaults standardUserDefaults] synchronize]; 

     self.initialViewController = [[InitialViewController alloc] initWithNibName:@"InitialViewController" bundle:nil]; 
     self.window.rootViewController = self.InitialViewController; 
     NSLog(@"first launch"); 
    } 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 
+0

확인 당신이의 ViewController를 만들 수있는 등 최적의 장소를 제안 무엇 멋지다 : 같은

변경하여 다른 조건? –

+0

@ user1805901 : 나는 당신을 얻지 못했습니다! 어떤보기 컨트롤러? –

+0

나는 그것을 지금 얻는다;) 고마워! –

관련 문제