无法更改SplitViewController中的方向

时间:2012-08-13 11:47:57

标签: objective-c xcode ipad

我对iPad应用程序SplitViewController不太熟悉。我在我的应用程序中使用了SplitViewController。将方向从纵向更改为横向时,Masterview将隐藏在splitView中。你能不能帮我解决这个问题。

我附上了我的资料供您参考。

创建SplitViewController:

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];     //在应用程序启动后覆盖自定义点。

menuViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController" bundle:nil];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:menuViewController] ;
masterNavigationController.navigationBar.barStyle = UIBarStyleBlack;

MainMenuDetailViewController *detailViewController = [[MainMenuDetailViewController alloc] initWithNibName:@"MainMenuDetailViewController" bundle:nil] ;
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController] ;
detailNavigationController.navigationBar.barStyle = UIBarStyleBlack;


self.splitViewController = [[UISplitViewController alloc] init];
[self.splitViewController.view setBackgroundColor:[UIColor whiteColor]];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];

DetailView页面:

pragma mark -

pragma mark拆分视图支持

  • (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController )aViewController withBarButtonItem:(UIBarButtonItem )barButtonItem forPopoverController:(UIPopoverController *)pc {

    barButtonItem.title = NSLocalizedString(@“Menu”,@“Menu”); [self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES]; self.masterPopoverController = pc; appDelegate.rootPopoverButtonItem = barButtonItem; appDelegate.masterPopoverController = pc; }

//在拆分视图中再次显示视图时调用,使按钮和弹出控制器无效。 - (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {

[self.navigationItem setLeftBarButtonItem:nil animated:YES];
self.masterPopoverController = nil;

}

MasterView按钮点按:

[appDelegate.splitViewController viewWillDisappear:YES];

[UIView  beginAnimations: @"Showinfo"context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];


NSMutableArray *viewControllerArray=[[NSMutableArray alloc] initWithArray:[[appDelegate.splitViewController.viewControllers objectAtIndex:1] viewControllers]];

[viewControllerArray removeLastObject];

if( viewMenu.hidden == YES)  // Main Menu
{
    if(btnMenu.tag == 1) // Service Report Form
    {
        if (!self.mainMenuDetailViewController) {
            self.mainMenuDetailViewController = [[MainMenuDetailViewController alloc] initWithNibName:@"MainMenuDetailViewController" bundle:nil];
        }
        [viewControllerArray addObject:self.mainMenuDetailViewController];
        appDelegate.splitViewController.delegate = self.mainMenuDetailViewController;

    }

    if(btnMenu.tag == 4) // Signout
    {
        [self.navigationItem setLeftBarButtonItem:nil];
        [appDelegate SignOut];
        btnSignOut.frame = CGRectMake(24,275,272,50);
    }
    else if(btnMenu.tag == 2) // Inquiries
    {
       if (!self.inquiryViewController) {
            self.inquiryViewController = [[InquiryViewController alloc] initWithNibName:@"InquiryViewController" bundle:nil] ;
        }


        [viewControllerArray addObject:self.inquiryViewController];
        appDelegate.splitViewController.delegate = self.inquiryViewController;
    }
    else if(btnMenu.tag == PageMasterSync)
    {

        if (!self.mastSyncViewController) {
            self.mastSyncViewController = [[MastSyncViewController alloc] initWithNibName:@"MastSyncViewController" bundle:nil] ;
        }
        appDelegate.splitViewController.delegate = self.mastSyncViewController;
        [viewControllerArray addObject:self.mastSyncViewController];
    }
    else if(btnMenu.tag == PageServiceReport)
    {
        if(!self.srListViewController)
       self.srListViewController  = [[SRListViewController alloc] initWithNibName:@"SRListViewController" bundle:nil];

        appDelegate.splitViewController.delegate = srListViewController;
        [viewControllerArray addObject:self.srListViewController];

    }


}


}


[[appDelegate.splitViewController.viewControllers objectAtIndex:1] setViewControllers:viewControllerArray animated:NO]; 
if(btnMenu.tag == PageReview &&  !viewMenu.hidden)
   [self.reviewViewController loadServiceReport];

[appDelegate.splitViewController viewWillAppear:YES];
[viewControllerArray release];

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO];
[UIView commitAnimations];

关心 塞特希enter image description here

0 个答案:

没有答案