在iOS 7中,在我的第一个UItableVIEwController里面,我只是打电话
[self.navigationController pushVIEwController:othertableVC animated:YES];
在iOS 8中:
拆分视图折叠后,其他表格变为详细视图!
然后旋转设备后,我们看到两张桌子并排…
更糟糕的是,如果设备显示两个窗格,则代码工作得很好,第二个表在主视图中被推送到第一个窗格.但是,在双轮之后,这两张桌子又是并列的.看起来UISplitVIEwController的折叠模式干扰我自己的导航控制器…
如何在主视图中管理我自己的UINavigationController?
谢谢
编辑:
我的主要和细节视图都有一个导航控制器.为了解决我的问题,我刚刚发现,在折叠模式下,我必须创建一个额外的导航控制器,并将其推送到主导航控制器上.
UINavigationController *navController = [[UINavigationController alloc] initWithRootVIEwController:othertableVC];[self.navigationController pushVIEwController:navController animated:YES];
所以我只是发现了帽子,我们可以在另一个导航控制器内部导航控制器.
解决方法 简短的答案,你可以通过UISplitVIEwControllerDelegate方法来控制这个行为:splitVIEwController:collapseSecondaryVIEwController:ontoprimaryVIEwController:splitVIEwController:separateSecondaryVIEwControllerFromPrimaryVIEwController:
我怀疑你真正想要做的是处理你有一个基于iOS 8 UISplitVIEwController的应用程序的情况,其中主要和详细的视图都是UINavigationControllers,并且有一些vIEwControllers(在这些导航控制器中),您只想出现在分割视图的主要或细节侧.下面的答案处理这个.它也可以处理您有时希望视图更换详细信息导航控制器中的视图而不是被推送到的情况.
一个小小的注意事项:下面的代码不处理所有可能的情况,并有一些假设:
>当拆分视图折叠,并且这些视图被其上方的详细视图遮蔽时,我们不希望在“详细”导航控制器堆栈上发生任何更改.
>我们的UIVIEwController子类都有一个shoulddisplayInDetailedVIEw和shouldReplaceDetailedVIEw属性
>我们假设我们只将视图推送到具有setdisplayInDetailedVIEw属性集的详细导航控制器上.
> VIEw控制器通过splitVIEwController添加到Detail侧:showDetailVIEwController:或pushVIEwController:animated:在详细视图(以展开或折叠状态)的视图的navigationController属性上.
>只能在Detail导览控制器中替换视图控制器的VIEw控制器只能通过splitVIEwController:showDetailVIEwController进行添加:仅在主视图控制器中与视图进行交互,即只有当主视图控制器在崩溃状态
>当分割视图控制器被扩展时,我们有一个BlankVIEwController显示在Detail VIEw中,但是我们只有一个应该保留在Primary侧的视图控制器.
我不建议仅执行splitVIEwController的一侧:collapseSecondaryVIEwController:toprimaryVIEwController:/ splitVIEwController:separateSecondaryVIEwControllerFromPrimaryVIEwController:逻辑,并取决于另一方的默认实现.苹果做一些奇怪的事情,如把UINavigationVIEwController从细节方面放到主要的一面,作为主导航控制器堆栈中的一个vIEwController,然后推送其上的其他视图控制器,即使您完全理解仍然无法复制你自己的代码因此,最好自己处理这个过程的双方.
这是我用的:
#pragma mark -#pragma mark Split VIEw Controller delegate.- (BOol)splitVIEwController:(UISplitVIEwController *)splitVIEwController showVIEwController:(UIVIEwController *)vc sender:(ID)sender{ //Standard behavIoUr. This won't get called in our case when the split vIEw is collapsed and the primary vIEw controllers are obscured. return NO;}// Since we treat warnings as errors,silence warning about unkNown selector below on UIVIEwController subclasses.#pragma GCC diagnostic ignored "-Wundeclared-selector"- (BOol)splitVIEwController:(UISplitVIEwController *)splitVIEwController showDetailVIEwController:(UIVIEwController *)vc sender:(ID)sender{ if (splitVIEwController.collapsed == NO) { // The navigation controller we'll be adding the vIEw controller vc to. UINavigationController *navController = splitVIEwController.vIEwControllers[1]; UIVIEwController *topDetailVIEwController = [navController.vIEwControllers lastObject]; if ([topDetailVIEwController isKindOfClass:[BlankVIEwController class]] || ([vc respondsToSelector:@selector(shouldReplaceDetailedVIEw)] && [vc performSelector:@selector(shouldReplaceDetailedVIEw)])) { // Replace the (expanded) detail vIEw with this new vIEw controller. [navController setVIEwControllers:@[vc] animated:NO]; } else { // Otherwise,just push. [navController pushVIEwController:vc animated:YES]; } } else { // Collapsed. Just push onto the conbined primary and detailed navigation controller. UINavigationController *navController = splitVIEwController.vIEwControllers[0]; [navController pushVIEwController:vc animated:YES]; } // We've handled this ourselves. return YES;}- (BOol)splitVIEwController:(UISplitVIEwController *)splitVIEwController collapseSecondaryVIEwController:(UIVIEwController *)secondaryVIEwController ontoprimaryVIEwController:(UIVIEwController *)primaryVIEwController{ UINavigationController *primaryNavController = (UINavigationController *)primaryVIEwController; UINavigationController *secondaryNavController = (UINavigationController *)secondaryVIEwController; UIVIEwController *bottomSecondaryVIEw = [secondaryNavController.vIEwControllers firstObject]; if ([bottomSecondaryVIEw isKindOfClass:[BlankVIEwController class]]) { NSAssert([secondaryNavController.vIEwControllers count] == 1,@"BlankVIEwController is not only detail vIEw controller"); // If our secondary controller is blank,do the collapse ourself by doing nothing. return YES; } // We need to shift these vIEw controllers ourselves. // This should be the primary vIEws and then the detailed vIEws on top. // Otherwise the UISplitVIEwController does wacky things like embedding a UINavigationController insIDe another UINavigation Controller,which causes problems for us later. NSMutableArray *newPrimaryVIEwControllers = [NSMutableArray arrayWithArray:primaryNavController.vIEwControllers]; [newPrimaryVIEwControllers addobjectsFromArray:secondaryNavController.vIEwControllers]; primaryNavController.vIEwControllers = newPrimaryVIEwControllers; return YES;}- (UIVIEwController *)splitVIEwController:(UISplitVIEwController *)splitVIEwController separateSecondaryVIEwControllerFromPrimaryVIEwController:(UIVIEwController *)primaryVIEwController{ UINavigationController *primaryNavController = (UINavigationController *)primaryVIEwController; // Split up the combined primary and detail navigation controller in their component primary and detail vIEw controller Lists,but with same ordering. NSMutableArray *newPrimaryVIEwControllers = [NSMutableArray array]; NSMutableArray *newDetailVIEwControllers = [NSMutableArray array]; for (UIVIEwController *controller in primaryNavController.vIEwControllers) { if ([controller respondsToSelector:@selector(shoulddisplayInDetailedVIEw)] && [controller performSelector:@selector(shoulddisplayInDetailedVIEw)]) { [newDetailVIEwControllers addobject:controller]; } else { [newPrimaryVIEwControllers addobject:controller]; } } if (newDetailVIEwControllers.count == 0) { // If there's no detailed vIEws on the top of the navigation stack,return a blank vIEw (in navigation controller) for detailed sIDe. UINavigationController *blankDetailNavController = [[UINavigationController alloc] initWithRootVIEwController:[[BlankVIEwController alloc] init]]; return blankDetailNavController; } // Set the new primary vIEws. primaryNavController.vIEwControllers = newPrimaryVIEwControllers; // Return the new detail navigation controller and vIEws. UINavigationController *detailNavController = [[UINavigationController alloc] init]; detailNavController.vIEwControllers = newDetailVIEwControllers; return detailNavController;}总结
以上是内存溢出为你收集整理的在iOS 8的UISplitViewController的主视图中有一个UINavigationController全部内容,希望文章能够帮你解决在iOS 8的UISplitViewController的主视图中有一个UINavigationController所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)