我有一个Master Detail View ipad应用程序。我想在单击单元格并加载某些内容时关闭/隐藏masterViewController
。当我点击表格单元格时,我正在DetailViewController
上加载一个单独的视图控制器。当我没有在detailView
上加载另一个视图时,它完全正常。单击表格行后,我该怎么做才能关闭masterViewController
。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[_detailViewController.navigationController pushViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"ABCViewController"] animated:YES];
}
答案 0 :(得分: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)在您的详细视图上写下此方法。
(无效)dismissPop {
if(self.interfaceOrientation == UIInterfaceOrientationPortrait) {
//self.popover is your reference to master view pop
if([self.popover isPopoverVisible])
{
[self.popover dismissPopoverAnimated:YES];
}
}
}