2014-06-26 53 views
1

我在使用IIViewDeck時遇到了困難。我正在使用故事板。我已經成功地將帶有單元格的leftviewcontroller放置在tableviewcontroller中,這些單元格應該在故事板中呈現給特定的viewcontroller。我該怎麼做呢?我已經把它放在了appdelegate中。如何從故事板中的IIViewDeck的leftviewcontroller中的特定視圖控制器?

UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil]; 

UIViewController *menuController = [mainStoryboard instantiateViewControllerWithIdentifier:@"mainSideNavMenu"]; 

UINavigationController* navigationController = (UINavigationController *) self.window.rootViewController; 
self->viewDeckController = [[IIViewDeckController alloc] initWithCenterViewController:navigationController leftViewController:menuController rightViewController:nil]; 
self.window.rootViewController = self->viewDeckController; 

回答

0

您可以使用代碼管理它,並使用表視圖的didSelectRowAtIndexPath方法。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 

if (indexPath.row == 0) { 
    MyTripsViewController* newController = [sb instantiateViewControllerWithIdentifier:@"ViewController1"]; 
    [self.viewDeckController closeLeftViewBouncing:^(IIViewDeckController *controller) { 
     self.viewDeckController.centerController = newController; 
    }]; 
} 
if (indexPath.row == 1) { 
    MyTripsViewController* newController = [sb instantiateViewControllerWithIdentifier:@"ViewController2"]; 
    [self.viewDeckController closeLeftViewBouncing:^(IIViewDeckController *controller) { 
     self.viewDeckController.centerController = newController; 
    }]; 
} 
else { 
    MyTripsViewController* newController = [sb instantiateViewControllerWithIdentifier:@"ViewController3"]; 
    [self.viewDeckController closeLeftViewBouncing:^(IIViewDeckController *controller) { 
     self.viewDeckController.centerController = newController; 
    }]; 
} 

}

所以,你必須確定你行/夫婦的viewController。

0

我知道這有點遲,但有人可能會在某個時候找到答案。

馬克斯的答案通常是一個很好的答案。然而,原始海報的問題有點含糊。他/她沒有指定是否需要在中央視圖控制器或左側視圖中進行轉換。

假設過渡是在左視圖控制器:

如果你想推過渡,你可以使用如下代碼:

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (indexPath.row == 0) { 
     UINavigationController * nc = (UINavigationController *)self.viewDeckController.leftController; 
     UIViewController * vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"yourView"]; // use the name of the view (not the navigation view controller) 
     [nc pushViewController:vc animated:YES]; 
    } 
} 

如果你想模態過渡,只需用以下代碼替換之前if語句子句中的代碼:

UIViewController * vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"yourViewName"]; // don't use the name of a navigation controller 
UINavigationController * nc = [[UINavigationController alloc] initWithRootViewController:vc]; 
[self presentViewController:nc animated:YES completion:nil]; 

此代碼中的導航控制器用於顯示導航欄。如果您不需要導航欄,只需省略導航控制器定義,然後將視圖控制器作爲參數傳遞給presentViewController: animated: completion:方法。

假定過渡是在中心視圖控制器:

可以使用麥克斯提供的代碼。請記住,他表現出新的視圖控制器的方法是通過更換現有中心視圖控制器。新的視圖控制器是既不推動也不模式地顯示。如果你想推新視圖控制器到現有的中心視圖控制器,你應該使用我介紹的代碼前兩件以上的過渡的方式相同。因此,它應該是這樣的:

推轉型:(下面的代碼應在第一段代碼if語句子句中替換代碼)

[self.viewDeckController closeLeftView]; 
UINavigationController * nc = (UINavigationController *)self.viewDeckController.centerController; 
[nc pushViewController:[[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"yourViewName"] parentViewController] animated:YES]; 

莫代爾介紹:(下面的代碼應更換if語句子句中的代碼中的第一塊代碼)

[self.viewDeckController closeLeftView]; 
UINavigationController * center = (UINavigationController *)self.viewDeckController.centerController; 
UIViewController * vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"yourViewName"]; 
UINavigationController * nc = [[UINavigationController alloc] initWithRootViewController:vc]; 
[center presentViewController:nc animated:YES completion:nil]; 
相關問題