SWRevealViewController icon indicating copy to clipboard operation
SWRevealViewController copied to clipboard

Problem re-showing UISplitViewController

Open thomers opened this issue 8 years ago • 16 comments

I have a MasterDetail storyboard setup as created by the Xcode 7 project template, using a UISplitViewController as front view controller (and additional setup in AppDelegate application didFinishLaunching) as described in https://github.com/John-Lluch/SWRevealViewController/issues/518 .

screen shot 2016-03-09 at 15 56 58
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];

    UIStoryboard *mainSB = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];

    UISplitViewController *splitVC = (UISplitViewController *) [mainSB instantiateViewControllerWithIdentifier:@"SplitVC"];
    splitVC.delegate = self;

    MasterViewController *masterVC = (MasterViewController *) [mainSB instantiateViewControllerWithIdentifier:@"MasterVC"];
    UINavigationController *masterNav = [[UINavigationController alloc] initWithRootViewController:masterVC];

    DetailViewController *detailVC = (DetailViewController *) [mainSB instantiateViewControllerWithIdentifier:@"DetailVC"];
    UINavigationController *detailNav = [[UINavigationController alloc] initWithRootViewController:detailVC];

    splitVC.viewControllers = @[masterNav, detailNav];

    // SWRevealViewController
    UINavigationController *navController = (UINavigationController *) splitVC.viewControllers[splitVC.viewControllers.count-1];
    navController.topViewController.navigationItem.leftBarButtonItem = splitVC.displayModeButtonItem;
    splitVC.delegate = self;

    SWRevealViewController *swRevealVC = [mainSB instantiateViewControllerWithIdentifier:@"SWRevealVC"];
    MenuTableViewController *menuVC = [mainSB instantiateViewControllerWithIdentifier:@"MenuVC"];
    [swRevealVC setFrontViewController:splitVC animated:YES];
    [swRevealVC setRearViewController:menuVC animated:YES];

    self.window.rootViewController = swRevealVC;
    [self.window makeKeyAndVisible];


After app launch, the SplitViewController shows the MasterViewController, I can select an item and show the DetailViewController - so far so good.

But when I open the menu, select a menu item to show a different UIViewController (via SWRevealViewControllerSeguePushController segue type), and then want to show the UISplitViewController again (also via SWRevealViewControllerSeguePushController), the Detail ViewController is shown, instead of the MasterViewController.

Do I have to setup something in code before the segue is performed (like in AppDelegate)?

thomers avatar Mar 09 '16 15:03 thomers

I do not see the point of having a split view controller with SWRevealViewController

iDevelopper avatar Mar 09 '16 15:03 iDevelopper

It's the Xcode default for universal Master-Detail-apps (no need for handling iPad and iPhones differently)

thomers avatar Mar 09 '16 15:03 thomers

Hi @thomers 1- I think you don't need to have a connection (segue) between the rear view and the UISplitView 2- Why are you using SWRevealViewControllerSegue all over your project. It should be used for rear and front views. That's it.

Souf-R avatar Mar 09 '16 15:03 Souf-R

It is not mandatory to use this default storyboard

iDevelopper avatar Mar 09 '16 15:03 iDevelopper

Thanks @Souf-R

  1. Hmm, but how do I show the split VC from the menu, if the user is shown a different view controller? What do I call in tableView:didSelectRowAtIndexPath: to show the split VC again?
  2. Have a look at the "official" RevealControllerStoryboardExample2 - the setup is similar there: screen shot 2016-03-09 at 16 58 29

thomers avatar Mar 09 '16 15:03 thomers

@iDevelopper Of course it's not mandatory - but how do you implement the automatic Master/Detail-split on iPads then?

thomers avatar Mar 09 '16 16:03 thomers

aaaah ok, I think your problem now is just with the portrait mode when using iPad. If so, I have the same issue then I disabled the portrait mode my app now is working in landscape mode only when using iPad

Souf-R avatar Mar 09 '16 16:03 Souf-R

@Souf-R Actually yes, I have the problem with iPad portrait mode also - but this is not the same problem I described here, since this one happens on iPhones and iPads, regardless of orientation.

thomers avatar Mar 09 '16 16:03 thomers

It seems my only option is to remove the UISplitViewController, create 2 separate storyboards (iPhone, iPad) and use the SWRevealViewController as in the RevealControllerStoryboardExample2. (?)

thomers avatar Mar 10 '16 08:03 thomers

If somebody could explain why use UISplitViewController with SWRevealViewController as SW is designed to replace UISplitViewController?

iDevelopper avatar Mar 10 '16 08:03 iDevelopper

@iDevelopper The way I understood it - SWRevealViewController can only show one UIViewController as "front".

If you take 1 min to create a new Xcode project based on the "MasterDetail" template, and run it on iPad simulator, you see that both the Master and the DetailViewController can be visible at the same time, using the bigger available screen estate on iPad better (but giving the user the option to hide the MasterVC, if he wishes). On iPhone, only the MasterVC or the DetailVC is shown at one point in time.

All this is done automatically, with only one storyboard, by using the UISplitViewController.

If you can tell me how I can achieve the same (showing MasterVC and DetailVC at the same time on iPad, with MasterVC hideable) using SWRevealViewController, I will be more than happy.

thomers avatar Mar 10 '16 09:03 thomers

Ok I'm watching!

iDevelopper avatar Mar 10 '16 09:03 iDevelopper

Is this is what you want to do?

SWSplitApp.zip

iDevelopper avatar Mar 11 '16 07:03 iDevelopper

Thanks, but no - in your project, the Master controller is the menu. What I need is the master controller as list (segueing to the detail controller) AND a menu controller, with the master controller as one of the view controllers that can be chosen from the menu. You see the structure in the image in my first post.

Anyway, I chose to ditch the SWR for my prototype and use a tab bar as "pseudo-menu" instead. Uglier, but works as universal storyboard out of the box!

Thanks for your work!

thomers avatar Mar 11 '16 07:03 thomers

In fact you want two SWRevealViewController?

iDevelopper avatar Mar 11 '16 07:03 iDevelopper

@thomers I know this is an old thread but did you ever come back to this and get the split view working with SWRevealViewController's menu?

chrisjmccrum avatar Mar 22 '18 18:03 chrisjmccrum