2010-05-18 198 views
3

我有一個要導航到UISplitView(另一種觀點完全內),像這樣的應用程序:這是主要的導航屏幕上做現在如何手動創建UISplitView?

- (void) switchToMyDayView { 
    NSLog(@"Show My Day Screen"); 

    if (self.myDayController.view.superview == nil) { 
     if (self.myDayController == nil) { 
      MyDayController *myController = [[MyDayController alloc] initWithNibName:@"MyDay" bundle:nil]; 
      self.myDayController = myController; 
      [myController release]; 
     } 

     [homeScreenController.view removeFromSuperview]; 
     [self.view insertSubview:self.myDayController.view atIndex:0]; 
    } 
} 

,該MyDayController有一個XIB叫MyDay.xib其中有以下項目:

File's Owner: MyDayController

First Responder: UIResponder

Split View Controller

---->Navigation Controller 

     ---->Navigation Bar 

     ----> Table View Controller 

       ----> Navigation Item 

---->View Controller 

所以,我需要一些更多的組件在這裏,我需要一個UITableViewController和UISplitViewControllerDelegate是否正確?

我打算只在MyDayController中實現這些協議,是這種標準嗎?

所以,上面的代碼後,我得到一個錯誤:

- [UIViewController中_loadViewFromNibNamed:束:]加載的「MyDay」筆尖但沒有設置視圖出口。

那麼,我怎樣才能解決它使用UISplitViewController?我知道UISplitViewController有一個視圖屬性,但我不能在IB中使用它/連接它嗎?

非常感謝

馬克

回答

5

你不應該有繼承UISplitViewController。你的「MyDayController」類中有什麼行爲? UISplitViewController基本上只是爲你處理主視圖和詳細視圖,所以你的責任是實現這些控制器。

如果拆分視圖位於應用程序的頂層,則可以將其添加到應用程序的主窗口筆尖。如果不是,只是創建它編程:

- (void) switchToMyDayView { 
    NSLog(@"Show My Day Screen"); 

    if (self.myDayController == nil) { 
     YourMasterViewController *masterViewController = [[YourMasterViewController alloc] initWithNibName:@"MasterView" bundle:nil]; 
     YourDetailViewController *detailViewController = [[YourDetailViewController alloc] initWithNibName:@"DetailView" bundle:nil]; 
     UISplitViewController *myController = [[UISplitViewController alloc] init; 
     myController.viewControllers = [NSArray arrayWithObjects:masterViewController, detailViewController, nil]; 
     [masterViewController release]; 
     [detailViewController release]; 

     self.myDayController = myController; 
     [myController release];   
    } 

    [homeScreenController.view removeFromSuperview]; 
    [self.view insertSubview:self.myDayController.view atIndex:0]; 
} 

還,如果你想在主機和詳細導航控制器創建不需要爲self.myDayController.view.superview == nil測試,因爲它是在self.myDayController == nil

0

我已經給了類似的問題here的AAN答案。

希望它有幫助。

感謝, Madhup

0

隱那麼你可以做到這一點

self.rootViewController=[[RootViewController alloc]init]; 
    self.detailViewController=[[FirstDetailViewController alloc]init]; 

    UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController]; 
    UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController]; 

    self.splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil]; 
    self.splitViewController.delegate=self.detailViewController; 
1

謝謝你克里斯托弗Pickslay。 這個解決方案適用於我,但我必須解決你給的東西。 請參閱下面的代碼。

委託文件

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

    LeftViewController *leftViewController = [[LeftViewController alloc] init];// initWithNibName:@"LeftViewController" bundle:nil]; 
    RightViewController *rightViewController = [[RightViewController alloc] initWithNibName:@"RightViewController" bundle:nil]; 
    UISplitViewController *myController = [[UISplitViewController alloc] init]; 
    myController.viewControllers = [NSArray arrayWithObjects:leftViewController, rightViewController, nil]; 

    self.window.rootViewController = myController; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 

希望這有助於。