0

我试图在横向模式下隐藏 UISplitView 中的主视图。我想通过单击按钮来执行此操作。在我的导航栏中,我有一个单击按钮,我想在横向模式下隐藏主视图。此外,如果主视图被隐藏,则单击同一按钮时,它应该显示主视图。所有这些都需要在主视图中完成。我提到了以下功能

-(BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
return YES;
}

但是,尽管单击按钮,它仍会在视图加载时隐藏主视图。下面是我的详细视图代码

- (void)setDetailItem:(id)newDetailItem {
if (detailItem != newDetailItem) {
[detailItem release];
detailItem = [newDetailItem retain];

        // Update the view.
        NSLog(@"Detail item in detail view::%@",detailItem);
        NSString *imageName = [NSString stringWithFormat:@"%@.jpg",[detailItem description]];
        NSLog(@"Image name is::%@",imageName);
        self.imageToDisplay.image = [UIImage imageNamed:imageName];
        [self configureView];
    }

    if (mainpopover != nil) {
        [mainpopover dismissPopoverAnimated:YES];
    }        
}

- (void)configureView 
{
    // Update the user interface for the detail item.  
    detailDescriptionLabel.text = [detailItem description];

    openInButton = [[UIBarButtonItem alloc] initWithTitle:@"OpenIn" style:UIBarButtonItemStyleDone target:self action:@selector(openIn)];
    favoritesButton = [[UIBarButtonItem alloc] initWithTitle:@"*" style:UIBarButtonItemStyleDone target:self action:@selector(markFavorite)];
    emailButton = [[UIBarButtonItem alloc] initWithTitle:@"E" style:UIBarButtonItemStyleDone target:self action:@selector(emailFile)];
    uploadButton = [[UIBarButtonItem alloc] initWithTitle:@"#" style:UIBarButtonItemStyleDone target:self action:@selector(uploadFile)];

    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:openInButton, favoritesButton,emailButton, uploadButton, nil];
}

#pragma mark -
#pragma mark Split view support

-(void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc
{
    barButtonItem.title = @"Quicksync";
    self.navigationItem.leftBarButtonItem = barButtonItem;
    self.mainpopover = pc;
}

// Called when the view is shown again in the split view, invalidating the button and popover controller.
-(void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    myBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"<" style:UIBarButtonItemStyleDone target:self action:@selector(hideMasterScreen)];
    self.navigationItem.leftBarButtonItem = myBarButtonItem;
    self.mainpopover = nil;
}

// Called when the hidden view controller is about to be displayed in a popover.
- (void)splitViewController:(UISplitViewController*)svc popoverController:(UIPopoverController*)pc willPresentViewController:(UIViewController *)aViewController
{
    // Check to see if the popover presented from the "Tap" UIBarButtonItem is visible.
    if ([barButtonItemPopover isPopoverVisible]) {
        // Dismiss the popover.
        [barButtonItemPopover dismissPopoverAnimated:YES];
    } 
}


-(BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
    return YES;
}
4

0 回答 0