splitViewController with Two NavigationController

2020-02-10 10:25发布

问题:

EDIT: Added Source Project

--> I uploaded a sample project that clearly shows my dilemma which can be found here <--

I created a Split View-based Application. I then added a second UINavigationController to the DetailViewController inside the MainWindow.xib.

I then pop a new UIViewController Subclasses when a toolbar item is clicked. I use the following code to conduct the pop:

DocumentDetailVC *DetailViewController = [[DocumentDetailVC alloc] initWithNibName:@"DocumentDetailVC" bundle:[NSBundle mainBundle]];
[detailViewController.detailNavController pushViewController:DetailViewController animated:YES];

DocumentsVC *RRequestViewController = [[DocumentsVC alloc] initWithNibName:@"DocumentsVC" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:RRequestViewController animated:YES];

This works. The issue I am having is how do I pass information or function calls from the Main side of the Split View to the Detail side of the Split view?

If I present the UIViewController via the following method:

DocumentDetailVC *RRequestViewController = [[DocumentDetailVC alloc] initWithNibName:@"DocumentDetailVC" bundle:[NSBundle mainBundle]];
RRequestViewController.delegate=self;
RRequestViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[RRequestViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:RRequestViewController animated:YES];
[RRequestViewController release];
RRequestViewController = nil;

I am able to complete a reach back through a protocol as intended.

DocumentDetailVC, when loaded via the pushViewController, the hierarchy is as follows:

NSLog([NSString stringWithFormat:@"%@",self]); 
//self = <DocumentDetailVC: 0x4e0d960>
NSLog([NSString stringWithFormat:@"%@",self.parentViewController]);
//self.parentViewController = <UINavigationController: 0x4e0ce30>
NSLog([NSString stringWithFormat:@"%@",self.parentViewController.parentViewController]);
//self.parentViewController.parentViewController = <UISplitViewController: 0x4e0d0f0>

Thank you for your assistance. This problem is consuming my life!

--> I uploaded a sample project that clearly shows my dilemma which can be found here <--

回答1:

Ok, I know am very late for answer but this answer is, I think, perfect and working. Try it. Open your RootViewController.h, on the top write this line:

#import "Left.h"
#import "Right.h"

in @interface RootViewController write this lines

Left *lefty;
Right *righty;

after that declare property as,

@property (nonatomic, retain) Left *lefty;
@property (nonatomic, retain) Right *righty;

go to ROOTVIEWCONTROLLER.M file synthesize as,

@synthesize lefty;
@synthesize righty;

after that in RootViewController.m just replace your function with this one

    - (IBAction)myBtnPushed{
    NSLog(@"myBtnPushed");


    lefty = [[Left alloc] initWithNibName:@"Left" bundle:[NSBundle mainBundle]];
    righty = [[Right alloc] initWithNibName:@"Right" bundle:[NSBundle mainBundle]];

    lefty.delegate=righty;
    [self.navigationController pushViewController:lefty animated:YES];

    [detailViewController.navigationController pushViewController:righty animated:YES];


}

in delloac write this,

[lefty release];
lefty = nil;
[righty release];
righty = nil;

It's done, run your app. I tested, it's done.