2
votes

I would like to create an application like this: enter image description here

On iphone (both portrait and landscape) and ipad portrait, I have a table view screen, tap on item row will navigate to another detail screen look like other basic application.
But when I rotate screen to go to landscape on ipad, the screen now has two section views
Here is what I did:

  • Write a method isInLandscapeTablet to detect ipad landscape
  • Use UINavigationController as a root controller to control all other views
  • In portrait screen, push a viewcontroller contains tableview to root controller
  • In landscape tablet screen, attach tableview controller and detail controller to UISplitViewController, then push it into root controller

But the problem is I can't push UISplitViewController to root controller, as it requires to be a root controller.
I wonder how I can handle this problem
And is my approach correct? Is there any other way?

Update: I change the root view controller like this

  // this snippet is in UINavigationController (I use as root viewcontroller) 
        if([self isInTabletLandscape]){
             self.splitViewController.viewControllers = [NSArray arrayWithObjects:[[CategoryViewController alloc] initWithNibName:@"CategoryViewController" bundle:nil], self.propertyLandViewController, nil];
            [[UIApplication sharedApplication].keyWindow setRootViewController:self.splitViewController];
        }else{
 // it doesn't work
            [[UIApplication sharedApplication].keyWindow setRootViewController:self];
            }
        }
4
You should have three different viewController - 1 for iPhone portrait, 1 for iPad portrait, 1 for iPad landscape (with splitViewController). push the correct viewcontroller to the rootViewCcontroller base on device type and orientation. If user rotate iPad, pop to the rootViewControler and push the correct viewController again. You can set a flag using delegate in the rootViewContoller to tell which viewContoller to push.Kilogen9
@Kilogen9 this is what I did. But as I said, the problem is I can't push UISplitViewController to root controller, as it requires to be a root controller.R4j
@R4j is the menu supposed to be static or always showing in landscape?valbu17
@NorthBlast it isn't really a menu. The view 1 always displays on the left on ipad landscape.R4j

4 Answers

1
votes

My suggestion is not to use Split View Controller at all. Create a custom View Controller, which will embed your table view controller and the 2nd controller. Also, you can implement the interface-rotation logic in the custom controller you create.

2
votes

After knowing the device whether it is iPad or iPhone. You Can try to remove the RootViewController.

       appDelegate.window.rootViewController = nil;

Then you set the root view controller with a new SplitViewContloller

        id objClass =[[SplitViewController alloc]initWithNibName:@"SplitViewController" bundle:nil];
        masterVC.delegate = detailVC;
        detailVC.delegate = objClass;
        [objClass setViewControllers:@[masterNavigate,detailNavigate]];

        [appDelegate.window setRootViewController:objClass];
1
votes

If you are developing on iOS 8 you should use Size Classes, so you can totally change the layout depending on iPhone/iPad portrait and iPad Landscape. Unfortunately on iOS 7, size classes only differentiate iPhone and iPad.

In both case the right part (2), can be easily handle with a containerView.

1
votes

https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/SplitViewControllers.html

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   MyFirstViewController* firstVC = [[MyFirstViewController alloc] init];
   MySecondViewController* secondVC = [[MySecondViewController alloc] init];

if ( ([[UIDevice currentDevice] orientation] ==  UIDeviceOrientationPortrait)  ){

   UISplitViewController* splitVC = [[UISplitViewController alloc] init];
   splitVC.viewControllers = [NSArray arrayWithObjects:firstVC, secondVC, nil];

    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    window.rootViewController = splitVC;
   [window makeKeyAndVisible];
 }
    else
{
// Display tableview

}
 return YES;
 }


I assume this may help you..