UISplitViewController检测到后退按钮被按下

时间:2015-04-07 15:43:29

标签: swift ios8 uisplitviewcontroller

我有一个UISplitViewController,我想始终显示iPad的主视图和详细视图控制器。这条线为我照顾:

// Always display master and detail in large screens
self.preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible

在prepareForSegue中,当打开详细视图控制器时,后面的按钮有以下几行代码

controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem()
controller.navigationItem.leftItemsSupplementBackButton = true

现在当用户按下该后退按钮时,我想在隐藏主视图控制器后执行操作。我没有找到如何做到这一点的运气。在SplitViewControllerDelegate中,我尝试使用:

func splitViewController(svc: UISplitViewController, willChangeToDisplayMode displayMode: UISplitViewControllerDisplayMode)

但是在Detail视图控制器变为全屏之前调用该函数。当UISplitViewController完成隐藏主视图时,是否有我可以做的功能或其他帮助通知我?

2 个答案:

答案 0 :(得分:0)

您可以在DetailViewController中的视图上添加观察者,并在触发时执行特定操作:

ChatVC *chatVC = [self.storyboard instantiateViewControllerWithIdentifier:@"chat"];
PrivateChatController * privateChatController = [self.storyboard instantiateViewControllerWithIdentifier:@"privatechat"];  
[self.navigationController pushViewController:privateChatController animated:YES];
NSMutableArray *viewControllers = [self.navigationController.viewControllers mutableCopy];
[viewControllers insertObject:chatVC atIndex:viewControllers.count - 2];
self.navigationController.viewControllers = viewControllers;

答案 1 :(得分:0)

您可以尝试使用delegate方法

- (UISplitViewControllerDisplayMode)targetDisplayModeForActionInSplitViewController:(UISplitViewController *)svc;