我目前正在将 ViewDeck 与 Storyboard 结合使用,并在应用程序 didFinishLaunchingWithOptions
中进行以下设置:
//View Deck Setup
UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
UIViewController* menuController = [mainStoryboard instantiateViewControllerWithIdentifier:@"LeftSideMenu"];
UINavigationController* navigationController = (UINavigationController *) self.window.rootViewController;
self.viewDeckController = [[IIViewDeckController alloc] initWithCenterViewController:navigationController leftViewController:menuController rightViewController:nil];
self.window.rootViewController = self.viewDeckController;
但是,当我从 MenuViewController 设置新的 CenterController
时,即使加载与我之前查看的相同的中心 View Controller ,导航栏也会被删除。
- (IBAction)viewUsers:(UIButton *)sender
{
UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
UIViewController* viewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"middleViewController"];
[self.viewDeckController setCenterController:viewController];
[self.viewDeckController closeLeftView];
}
我做错了什么?
最佳答案
解决方案是删除 AppDelegate 和 TabBar 之间的任何“甲板构造函数”类。当您需要设置或更改 Deck 结构时,我为每一种结构创建几种方法。例如,如果您希望 Deck 在左侧具有“leftView” View Controller ,在右侧具有“rightView”,在中心具有“tabBarHome”,请在 App Delegate 中创建如下方法:
-(void) lanzarHome{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
IIViewDeckController* deckController =[[IIViewDeckController alloc] initWithCenterViewController:[storyboard instantiateViewControllerWithIdentifier:@"tabBarHome"]
leftViewController:[storyboard instantiateViewControllerWithIdentifier:@"leftView"]
rightViewController:[storyboard instantiateViewControllerWithIdentifier:@"rightView"]];
deckController.leftSize = 100;
self.window.rootViewController = deckController;
[self.window makeKeyAndVisible];
}
现在,您必须使用如下语句从 viewController 调用此方法:
[((VKAppDelegate*) [[UIApplication sharedApplication] 委托(delegate)]) lanzarHome];
最重要的想法是创建从 AppDelegate 更改或初始化 Deck 结构的方法,并且在委托(delegate)和中心 TabBar 之间永远不会有另一个类或 viewController。
希望这个答案能解决您的问题。对我来说,找出这个问题是一项非常艰巨的工作。
关于ios - ViewDeck 在设置中心 Controller 时删除导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18681015/