我正在使用
UISplitViewController
,我需要隐藏 第一MasterViewController
DetailViewController
。手段,当app 启动时,必须隐藏MasterViewController
而不点击 任何UIButton
。我尝试在里面使用UISplitViewController
UIViewControllers
。但没有任何事情发生。之后,我尝试在UISplitViewController
内开发整体应用。这是我试图隐藏的代码MasterViewController
masterViewController = [splitViewController.viewControllers objectAtIndex:0];
detailVC = [splitViewController.viewControllers objectAtIndex:1];
[master.view setFrame:CGRectMake(0, 0, 0, 0)];
detail.view.frame = splitViewController.view.bounds;
我花了我一个星期这样做,但没有任何效果。请提供 解决方案。很高兴。
更新:
完成隐藏主视图控制器。但是当我设置委托时 详细视图控制器,它隐藏所有视图的主视图控制器 控制器。这是我添加的appDelegate代码
UISplitViewController
。
self.splitViewController =[[UISplitViewController alloc]init];
MasterTableViewController *masterViewController=[[MasterTableViewController alloc]initWithNibName:@"MasterTableViewController" bundle:nil];
UINavigationController *masterNavigate=[[UINavigationController alloc]initWithRootViewController:masterViewController];
DetailViewController *detailVC=[[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil];
UINavigationController *detailNavigate=[[UINavigationController alloc]initWithRootViewController:detailVC];
self.splitViewController.viewControllers=[NSArray arrayWithObjects:masterNavigate,detailNavigate, nil];
self.splitViewController.delegate=detailVC;
self.window.rootViewController=self.splitViewController;
在这里,我将splitViewController的委托设置为detailVC.In 带有Nex Mishra代码的detailViewController我隐藏了主视图 控制器,当我从detailVC导航到其他视图时,它隐藏起来 主视图控制器。我知道这会很烦人,但它会 很有帮助。
答案 0 :(得分:2)
您可以使用此委托方法隐藏主VC。
- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
//Add your own logic to when you want the master VC hidden.
return YES;
}
答案 1 :(得分:1)
- (BOOL)splitViewController:(UISplitViewController*)svc
shouldHideViewController:(UIViewController *)vc
inOrientation:(UIInterfaceOrientation)orientation
{
// this commant is used for showing or hiding the split view controller
svc.presentsWithGesture = TRUE;
return YES;
}
// dont forget to assign the delegate like this in viewWillAppear
(self.splitViewController.delegate = self;)