Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UISplitViewController-弹出详细信息时弹出主控形状(反之亦然)_Ios_Uinavigationcontroller_Uisplitviewcontroller - Fatal编程技术网

Ios UISplitViewController-弹出详细信息时弹出主控形状(反之亦然)

Ios UISplitViewController-弹出详细信息时弹出主控形状(反之亦然),ios,uinavigationcontroller,uisplitviewcontroller,Ios,Uinavigationcontroller,Uisplitviewcontroller,我有一个UISplitViewController,它的主VCs和详细VCs都是UINavigationController子类。 两者应该“同步”工作,也就是说,当一个人推一个新的VC时,第二个人也必须推一个。当一个爆裂时,另一个也必须爆裂。一个总是触发另一个相同的动作 我已经能够处理问题的推送部分,因为推送函数在我使用的每个类中都是显式的 另一方面,弹跳是一个大问题。当用户按下后退按钮时会触发该操作,我不知道如何检测该事件。一种可能的解决方案是检测事件 我想到的另一个解决方案是重写UINav

我有一个
UISplitViewController
,它的主VCs和详细VCs都是
UINavigationController
子类。 两者应该“同步”工作,也就是说,当一个人推一个新的VC时,第二个人也必须推一个。当一个爆裂时,另一个也必须爆裂。一个总是触发另一个相同的动作

我已经能够处理问题的推送部分,因为推送函数在我使用的每个类中都是显式的

另一方面,弹跳是一个大问题。当用户按下后退按钮时会触发该操作,我不知道如何检测该事件。一种可能的解决方案是检测事件

我想到的另一个解决方案是重写
UINavigationController
-popViewControllerAnimated:,使一个类弹出另一个类,如下所示:

// On DetailNav
- (UIViewController *)popViewControllerAnimated:(BOOL)animated {
  // Code to make MasterNav pop

  return [super popViewControllerAnimated:animated];
}

// On MasterNav
- (UIViewController *)popViewControllerAnimated:(BOOL)animated {
  // Code to make DetailNav pop

  return [super popViewControllerAnimated:animated];
}
我没有费心添加完整的代码,因为这足以注意到这种方法将导致无限循环,最终将两个NavController弹出到它们的根(然后可能崩溃)

实现所需行为的最佳方法是什么?

对于iOS 5+,
-(BOOL)是从ParentViewController移动的,它的诀窍是:

// Use this in the detail VC
- (void)viewWillDisappear:(BOOL)animated {
  [super viewWillDisappear:animated];

  if (self.isMovingFromParentViewController) {
    // the view is being popped. 
    // so also pop the master VC 
  }
}
我找到了另一个问题的答案

基本上,您需要两个子类
UINavigationController
,一个用于master,一个用于detail

在这两个子类中,必须包含
UINavigationBarDelegate
,并将委托设置为
self
. 然后包括以下方法:

- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item {
  [[[[self splitViewController] viewControllers][0 or 1] navigationController] performSelector:@selector(popViewControllerAnimated:) withObject:@YES afterDelay:0];
  return YES;
}
-(BOOL)导航栏:(UINavigationBar*)导航栏应为选项:(UINavigationItem*)项{
[[[self splitViewController]ViewController][0或1]navigationController]性能选择器:@selector(popViewControllerAnimated:),对象:@YES afterDelay:0];
返回YES;
}
在主视图中,您需要弹出详细信息VC,因此在索引上放置一个
1

在详细视图中,您需要弹出主视图VC,因此在索引上放置一个
0

此解决方案允许您在弹出视图控制器之前运行例程

更新

我遇到一些导航栏错误,例如
嵌套的pop动画会导致导航栏损坏。因此,我没有直接调用
popViewControllerAnimated:
而是以零延迟调用了
performSelector:
,现在当我弹出我的视图时,没有什么不好的事情发生。

它不会像以前一样陷入循环吗?因为如果我从Master弹出,细节控制器将在代码中输入
if
语句,对吗?