UISplitViewcontroller with the UINavigationController wizard and UINavigationController detail

We have the specific behavior that is required in our UISplitViewController application. We have the following hierarchy of 3 views

  • FormOneViewController - TableViewController built into MasterView
  • FormTwoViewcontroller - TableViewCotnroller initalised in detail.
  • FormThreeViewcontroller - not yet displayed.

When the user selects an item in the FormTwoViewController, we want the FormThreeViewCOntroller to appear in the detailView and FormTwoViewController (the current detailed view) to become the masterView.

We also need to have a return button on the detail view in order to return the view dispatch stack. Therefore, when the back button is pressed, FormTwoViewController becomes a detailView element, and FormOneViewController becomes main again.

We tried to implement this using the UISPlitViewcontroller and using the masterNavigationController and detailNavigationController. We have the initial stage of work, when the views are displayed correctly when the application starts, we select the FormTwoViewController element and click FormThreeViewController on the detailNavigationController, and FormTwoViewController is pushed onto the masterNavigationController stack.

The task that we have now is twofold

  • When you click on a button in the detail view controller, it does nothing. the handlers seem to be disabled or something like that.
  • We do not get a button in portrait mode to display the main view in a popover.

Does anyone have any examples of how to do this or any help would be appreciated.

+4
source share
1 answer

yes, you can do it, but you need to create a separate view controller for the master and parts, create a new project as a split view controller and remove the split view from xib so that we create a split view from the code.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after app launch. self.splitViewController =[[UISplitViewController alloc]init]; self.rootViewController=[[RootViewController alloc]init]; self.detailViewController=[[DetailViewController alloc]init]; UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController]; UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController]; // Add the split view controller view to the window and display. self.splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil]; self.splitViewController.delegate=detailViewController; [self.window addSubview:self.splitViewController.view]; [self.window makeKeyAndVisible]; return YES; } 

where rootviewcontroller is an urn format and the detailed view controller is ur forming two.

in the detail view controller, i.e. ur form two create class variable SplitViewAppDelegate * appDelegate; // delegate id id ur app set the property and synthesize it.

then in ur form two

 - (void)viewDidLoad { self.appDelegate = (SplitViewAppDelegate *)[[UIApplication sharedApplication] delegate]; } 

and finally by clicking ur, create three

 - (IBAction)pushViewController:(id)sender{ NSLog(@"%@",self.appDelegate.splitViewController.viewControllers); RootLevel1 *rootLevel1 =[[RootLevel1 alloc]init];//create form 1 root vc and assign form 1 vc DetailLevel1 <UISplitViewControllerDelegate>*detailLevel1=[[DetailLevel1 alloc]init]; UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle: @"Home" style:UIBarButtonItemStylePlain target:self action:@selector(home)]; rootLevel1.navigationItem.leftBarButtonItem=backButton; [self.appDelegate.splitViewController viewWillDisappear:YES]; [[self.appDelegate.splitViewController.viewControllers objectAtIndex:0] pushViewController:rootLevel1 animated:YES]; [[self.appDelegate.splitViewController.viewControllers objectAtIndex:1] pushViewController:detailLevel1 animated:YES]; self.appDelegate.splitViewController.delegate = detailLevel1; [self.appDelegate.splitViewController viewWillAppear:YES]; } 

and to start the view controller

 -(void)home { [self.splitViewController viewWillDisappear:YES]; [[self.appDelegate.splitViewController.viewControllers objectAtIndex:0]popViewControllerAnimated:YES]; [[self.appDelegate.splitViewController.viewControllers objectAtIndex:1]popViewControllerAnimated:YES]; UIViewController <UISplitViewControllerDelegate>*viewController=[[self.appDelegate.splitViewController.viewControllers objectAtIndex:1] visibleViewController]; self.splitViewController.delegate=viewController; [self.splitViewController viewWillAppear:YES]; } 

set ur splitview delgeate accordingly.

+10
source

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


All Articles