Конечно, вы можете использовать более одного detailviewcontroller
в UISplitviewcontroller
. Смотрите этот код.
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.rootVC = [[MasterViewController1 alloc]init];
self.detailVC = [[DetailViewController alloc]init];
UINavigationController *DetailNav = [[UINavigationController alloc]initWithRootViewController:self.detailVC];
SplitVC = [[UISplitViewController alloc]init];
SplitVC.viewControllers = [[NSArray alloc]initWithObjects:self.rootVC, DetailNav, nil];
SplitVC.delegate = self.detailVC;
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
self.window.rootViewController = SplitVC;
[self.window makeKeyAndVisible];
return YES;
}
В Masterviewcontroller.m
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = indexPath.row;
[self.appDelegate.SplitVC viewWillDisappear:YES];
NSMutableArray *viewControllerArray=[[NSMutableArray alloc] initWithArray:[[self.appDelegate.SplitVC.viewControllers objectAtIndex:1] viewControllers]];
[viewControllerArray removeLastObject];
if (row == 0)
{
self.detailViewController = [[DetailViewController alloc] init];
[viewControllerArray addObject:self.detailViewController];
self.detailViewController.detailItem = self.detailViewController;
self.appDelegate.SplitVC.delegate = self.detailViewController;
}
if (row == 1)
{
self.currencyVC = [[CurrencyConvertorViewController alloc]init];
[viewControllerArray addObject:self.currencyVC];
self.currencyVC.detailItem = self.currencyVC;
self.appDelegate.SplitVC.delegate = self.currencyVC;
}
if (row == 2)
{
self.latest = [[PhoneExample alloc]init];
[viewControllerArray addObject:self.latest];
self.latest.detailItem = self.latest;
self.appDelegate.SplitVC.delegate = self.latest;
}
if (row == 3)
{
self.settingsVC = [[SettingPage alloc]init];
[viewControllerArray addObject:self.settingsVC];
self.settingsVC.detailItem = self.settingsVC;
self.appDelegate.SplitVC.delegate = self.settingsVC;
}
[[self.appDelegate.SplitVC.viewControllers objectAtIndex:1] setViewControllers:viewControllerArray animated:NO];
[self.appDelegate.SplitVC viewWillAppear:YES];
}
В каждом контроллере detailview Добавить этого делегата UISplitViewControllerDelegate, UIPopoverControllerDelegate
detailViewcontroller.m
-(void)viewDidLoad
{
[super viewDidLoad];
self.appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc {
barButtonItem.title = @"Master";
self.appDelegate.popoverController = pc;
[[self navigationItem] setLeftBarButtonItem:barButtonItem];
self.appDelegate.rootPopoverButtonItem = barButtonItem;
}
- (void)splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
[[self navigationItem] setLeftBarButtonItem:nil];
self.appDelegate.popoverController = nil;
self.appDelegate.rootPopoverButtonItem = barButtonItem;
}
Прагма Марк - Поддержка вращения
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
[[self navigationItem] setLeftBarButtonItem:nil];
}
else
{
[[self navigationItem] setLeftBarButtonItem:self.appDelegate.rootPopoverButtonItem];
}
}