UISplitViewController on a universal application with storyboards

I want to create an application using UISplitViewControlerthe iPad (as I understand it, this is only available on the iPad), but I want the application to be universal.

The setup looks like this:

I have UITableView(as the main view), and when I select a row, it should display a detailed view of this cell. I use storyboards and I can’t figure out how to implement split view for iPad only.

What would be the easiest way to achieve this? Thanks.

+4
source share
1 answer

. . iphone SWRevealViewController ( iOS..:)) splitviewcontroller ipad. SWRevealViewController ipad. .

viewcontrollers size Classes ( ).

view ipad iphones . .

view, appdelegate, instantiateViewcontrollerWithIdentifier, .

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  // The device is an iPad running ios 3.2 or later.

}
else {
  // The device is an iPhone or iPod touch.
}

ipad splitview. swrevealviewcontroller iPhone.

. , .

VC (viewcontroller) ? vc . , iphone ipad ( ). vc VC. appdelegate. ipad, appdelegate didFinishLaunchingWithOptions

, . tutorilal swrevealcontroller splitVC . SWrevealVC splitViewcontroller , .

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
    {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UISplitViewController *split = [storyboard instantiateViewControllerWithIdentifier:@"SplitViewController"];
        [AppDelegate setRootController:split storyboard:storyboard actiontype:0];
    }
    else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController *split = [storyboard instantiateViewControllerWithIdentifier:@"SWrevealVC"];
        [AppDelegate setRootController:split storyboard:storyboard actiontype:-1];
    }
return YES;
}

+(void)setRootController:(UIViewController*)controller
              storyboard:(UIStoryboard*)storyboard actiontype:(int) actiontype;
{
    if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && actiontype == 0)
    {
        UISplitViewController *splitViewController = (UISplitViewController *)controller;
        //splitViewController.presentsWithGesture = false;

        UINavigationController *masterNavigationController = [splitViewController.viewControllers objectAtIndex:0];
        SideMenuViewController *controller = (SideMenuViewController *)masterNavigationController.topViewController;
        controller.splitViewController = splitViewController;
        splitViewController.delegate = (id)controller;
    }

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

    [UIView
     transitionWithView:appDelegate.window
     duration:0.5
     options:UIViewAnimationOptionAllowAnimatedContent
     animations:^(void) {
         BOOL oldState = [UIView areAnimationsEnabled];

         [UIView setAnimationsEnabled:NO];

         appDelegate.window.rootViewController = controller;

         [UIView setAnimationsEnabled:oldState];
     }
     completion:nil];
}

, . , -.

+1

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


All Articles