Programmatically disable the detail view manager in a collapsible display?

Question

On the minimized UISplitViewController screen, how can I programmatically return to the main controller?

Detail

I googled but did not find a solution. Not sure if I used the correct keyword. This is how I show the detail view controller:

[self showDetailViewController:[[UINavigationController alloc] initWithRootViewController:detail] sender:self]; 

I also tried these 3 methods, but none of them worked:

 if (self.splitViewController.collapsed) { UIBarButtonItem *backButtonItem = self.navigationItem.leftBarButtonItem; (1):[backButtonItem.target performSelector:backButtonItem.action]; (2):[[UIApplication sharedApplication] sendAction:backButtonItem.action to:backButtonItem.target from:nil forEvent:nil]; (3):objc_msgSend(backButtonItem.target, backButtonItem.action); } 

navigation elements set in detail in detail VC viewDidLoad:

 self.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem; self.navigationItem.leftItemsSupplementBackButton = YES; 
+3
source share
3 answers

Ok, I found a solution that seems to work. I tested it on the iPhone 6 and iPhone 6 Plus, but I just opened it thirty minutes ago, so it might have some unfortunate side effect that I haven't confused yet.

It is fast. I hope this is clear. Let me know if you want me to provide it in Objective-C.

 if let splitViewController = splitViewController { if splitViewController.collapsed { let viewControllers = splitViewController.viewControllers for controller in viewControllers { // PrimaryNavigationController is the navigation controller I use // as the split views master view, which is also set as its delegate // but it could be any UINavigationController that is the // primary controller of the split view if controller.isKindOfClass(PrimaryNavigationController) { controller.popViewControllerAnimated(true) } } } } 

I call this from my detailed view when I want to reject it.

This code works by checking if the controller of the split view is compensated, which is the only state where the popup view of the part makes sense (for me it doesn't matter). He then simply searches for the navigation controller that is currently playing in the split view controller and asks him to put it in the top-level controller. This works because, in collapse mode, the split view view mode is the only view controller on the stack. The detailed view collapses "into" it and, therefore, becomes the current controller of its top view, thus the one that appears.

It seems to need work. Let me know if this is for you too.

+2
source

I wanted to do the same, and this code worked for me. I placed it in a detailed view by connecting it to a button in the navigation bar.

In my application, the detailed view can go over to itself several times, and this code returns to the main view, no matter how deep it gets along the line.

 @IBAction func unwindSegueId(sender: AnyObject) { if (self.splitViewController!.collapsed) { self.splitViewController!.viewControllers[0].popToRootViewControllerAnimated(true) } } 
+2
source

This seems to work (if there is a navigation controller in your master panel)

 if (self.splitViewController.collapsed) { [(UINavigationController *)self.splitViewController.viewControllers[0] popToRootViewControllerAnimated:YES]; } 
+1
source

Source: https://habr.com/ru/post/986812/


All Articles