2012-03-21 74 views
2

我是UISplitView開發的新手,所以我確信有一些明顯的我做錯了。我有一個基本的UISplitView iPad應用程序,當應用程序啓動時加載兩個UITableView控制器。這工作得很好。問題呈現在UISplitView加載後以模態方式查看

我試圖做的是立即啓動,以模態方式呈現「身份驗證」視圖,以便用戶在繼續之前需要登錄。這是我迄今爲止的代碼編譯和工作沒有中斷,但沒有顯示視圖。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil]; 
    UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController]; 

    DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; 
    UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController]; 

    self.splitViewController = [[UISplitViewController alloc] init]; 
    self.splitViewController.delegate = detailViewController; 
    self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil]; 

    masterViewController.detailViewController = detailViewController; 
    masterViewController.managedObjectContext = self.managedObjectContext; 

    self.window.rootViewController = self.splitViewController; 
    [self presentAuthenticate]; 
    [self.window makeKeyAndVisible]; 

    applicationDidLaunch = YES; 
    return applicationDidLaunch; 
} 

- (void) presentAuthenticate { 
    AuthenticateViewController *loginController = [[AuthenticateViewController alloc] initWithNibName:@"AuthenticateViewController" bundle:nil]; 
    [loginController setModalTransitionStyle:UIModalTransitionStyleCoverVertical]; 
    [loginController setModalPresentationStyle:UIModalPresentationFormSheet]; 

    if ([self.splitViewController respondsToSelector:@selector(presentViewController:animated:completion:)]) { 
     [self.splitViewController presentViewController:loginController animated:NO completion:nil]; 
    } else { 
     [self.splitViewController presentModalViewController:loginController animated:NO]; //iOS 4 works fine with or without animation 
    } 
} 

我將AuthenticateViewController定義爲一個視圖,其中包含幾個文本框並將其連接到文件的所有者視圖。

提前致謝!

回答

2

除非和直到視圖完成加載,否則ViewController將不允許推送/呈現在另一個視圖上。

簡單的說我們不允許在viewcontroller中調用presentModalViewController/pushViewController viewDidLoad/viewWillAppear。我們需要在viewDidAppear中調用它。

我有同樣的問題,你說。

一些解決方案,我可以說是,

  1. 後做AuthenticateViewController的裝載[self.window makeKeyAndVisible]並在一個performSelctor(可能有一個延遲)。
  2. 移動代碼以在SplitView的DetailView控制器viewDidAppear中顯示AuthenticateViewController。

感謝,

納文珊

+0

我與你選擇2號去了,它工作正常,謝謝! – rwyland 2012-03-25 02:56:07