John-Lluch / SWRevealViewController

A UIViewController subclass for presenting side view controllers inspired on the FaceBook and Wunderlist apps, done right !
Other
4.52k stars 988 forks source link

Problem re-showing UISplitViewController #559

Open thomers opened 8 years ago

thomers commented 8 years ago

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)?

iDevelopper commented 8 years ago

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

thomers commented 8 years ago

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

Souf-R commented 8 years ago

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.

iDevelopper commented 8 years ago

It is not mandatory to use this default storyboard

thomers commented 8 years ago

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 commented 8 years ago

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

Souf-R commented 8 years ago

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

thomers commented 8 years ago

@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 commented 8 years ago

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

iDevelopper commented 8 years ago

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

thomers commented 8 years ago

@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.

iDevelopper commented 8 years ago

Ok I'm watching!

iDevelopper commented 8 years ago

Is this is what you want to do?

SWSplitApp.zip

thomers commented 8 years ago

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!

iDevelopper commented 8 years ago

In fact you want two SWRevealViewController?

chrisjmccrum commented 6 years ago

@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?