2014-01-06 45 views
0

我是iPad的開發人員,我想分割視圖。我有一個左邊的菜單(像一個標籤欄,但垂直和左側),一個標題(對於所有視圖已經是相同的)和一​​些數據在屏幕中心的容器...iPad上的拆分視圖,建議?

我' m使用故事板(也是啓動器)。

該應用程序的結構看起來像一個網頁。在故事板中,我使用3個容器:

  • 1爲我的左菜單
  • 1爲我的頭
  • 1爲我的主容器。

問題是:如何刷新我的主容器與我的項目菜單對應的數據?

示例:在項目1

  • 菜單=> TAPP =>顯示從Item1ViewController在 主容器數據
  • 菜單=>從Item2ViewController項目2 =>的顯示數據在 主容器
  • TAPP上項目3
  • 菜單=> TAPP =>顯示從Item3ViewController在 主容器數據

...

你明白我的意思了嗎?這裏是我的故事板結構:

enter image description here

謝謝大家對您的建議和解釋,我真的居然瘦了。

更新1:

我試過,但我有一些問題,我知道明白: 首先,這裏是我的AppDelegate方法didFinishLaunchingWithOptions:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 

    self.mainViewController = [[MainContainerViewController alloc] init]; // MainContainer which can be refreshed with some other viewControllers... 

    self.dashboardController = [[DashboardViewController alloc] init]; // The first viewController to load in the mainViewController 

    [self setDetailViewController:self.dashboardController]; // Method to set the viewController I want to load in the mainViewController 

    [self setup]; 

    return YES; 
} 

方法來設置德的viewController:

- (void)setDetailViewController:(id)controller 
{ 
    self.mainViewController = controller; 
} 

我在故事板中設置了一個viewController,它是MainViewControll的一個類er(主容器...)和一個ViewController,它是DashboardViewController的一個類。 當應用程序啓動時,我的DashboardViewController的viewDidLoad方法不被調用,只有init方法,爲什麼?

這裏我的故事板看起來像:

enter image description here

感謝您的幫助!;)

回答

0
  1. 您的應用程序委託文件中創建兩側menuViewController和mainViewController
  2. 在你menuViewController文件,你會當然有你的含 所有菜單項表,當選擇將調用方法會是這個樣子

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
        NSString *methodToCall = [[[[self.menuTitles objectAtIndex:indexPath.section] valueForKey:@"RowTitles"] objectAtIndex:indexPath.row] valueForKey:@"method"]; 
        if([methodToCall length] > 0){ 
         SEL s = NSSelectorFromString(methodToCall); 
         [self performSelector:s]; 
        } 
    } 
    

在這裏我只是存放我所有的菜單標題以及它們的方法名稱在一個NSMutableDictionary並調用它們的Appro公司自選選擇器。或者你可以做一個簡單的if else語句,

if(indexPath.row == 0){ 
    [self loadNewScreenOnMainController]; 
} 

,並在選擇我做這樣的事情:

-(void)loadNewScreenOnMainController{ 
    ProductsVC *productsVC = [[ProductsVC alloc] init]; 
    UINavigationController *productsNav = [[UINavigationController alloc] initWithRootViewController:productsVC]; 
    [[AppDelegate appDelegate] setDetailViewController:productsNav]; 
} 

}

的想法是調用一個方法在您的應用程序委託,將從sidemenu視圖控制器切換mainViewcontroller與視圖控制器

然後在你的`appDelegate.m文件中,你將有一個看起來像這樣的方法:

-(void)setDetailViewController:(id)newController{ 
    mainViewController = newController; 
} 

看一看Matt gemmett's splitviewcontroller example,他使用這個同樣的方法到一個新的視圖控制器從sidemenuViewcontroller切換到主視圖 - 控制

+0

謝謝你對我的幫助!我現在嘗試;) – Lapinou

+0

@Lapinou我已經爲你完成了答案,其中還包括一個關於wat的想法,將你的應用程序委託放入你的最終主控制器交換機。 – Pavan

+0

嗨帕文!感謝您的幫助;)我嘗試使用您的想法,但我遇到了一些問題。如果您想查看我的問題,我已更新我的帖子。非常感謝你 ;) – Lapinou