我正试图在横向模式下隐藏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;
}