我想在仅在iPad处于纵向视图时选择单元格时隐藏主视图控制器。因此,用户将单击该单元格,然后主视图控制器将消失(如在Mail中)。我在哪里以及如何做到这一点?
答案 0 :(得分:8)
配置详细视图控制器后,需要关闭弹出控制器。
if (self.popoverController) {
[self.popoverController dismissPopoverAnimated:YES];
}
如果您的详细视图控制器还没有用于保存UIPopoverController
的属性,则可以通过为UISplitViewControllerDelegate
- (void)splitViewController:(UISplitViewController *)iSplitViewController
willHideViewController:(UIViewController *)iViewController
withBarButtonItem:(UIBarButtonItem *)iBarButtonItem
forPopoverController:(UIPopoverController *)iPopoverController {
self.popoverController = iPopoverController;
}
- (void)splitViewController:(UISplitViewController *)iSplitViewController
willShowViewController:(UIViewController *)iViewController
invalidatingBarButtonItem:(UIBarButtonItem *)iBarButtonItem {
self.popoverController = nil;
}
答案 1 :(得分:0)
获取注册以获取有关详细视图的通知。
1)在您的详细信息视图中,获取通知注册。
- (void) viewDidLoad
{
//for showing loginview
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(dismissPop) name:@"MASTERROWSELECTED" object:nil];
}
2)在didSelectRowAtIndexPath的主视图上执行此操作;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//do normal things you usually do
//post notification that row is selected and you need to dismiss popover.
[[NSNotificationCenter defaultCenter] postNotificationName:@"MASTERROWSELECTED"
object:nil];
}
3)在您的详细信息视图中写下此方法。
- (void)dismissPop
{
if(self.interfaceOrientation == UIInterfaceOrientationPortrait)
{
//self.popover is your reference to master view pop
if([self.popover isPopoverVisible])
{
[self.popover dismissPopoverAnimated:YES];
}
}
}
答案 2 :(得分:-1)
您可以使用自定义SplitViewController(如Matt Gemmell的MGSplitViewController)来实现此目的。特别是,此实现向控制器添加了toggleMasterView:
方法,您可以在didSelectRowAtIndexPath:
内调用该方法。