这是一个老帖子,但我发现它有用的帮我想以不同的方式,这是我如何解决问题。
我以编程方式创建了我的splitViewController
。然后我用一个数字标记它,并将其作为子视图添加到当前视图中。
FirstViewController* firstView = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
SecondViewController* secondView = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
UISplitViewController* splitVC = [[UISplitViewController alloc] init];
[splitVC setDelegate:secondView];
splitVC.viewControllers = [NSArray arrayWithObjects:firstView, secondView, nil];
splitVC.view.tag = 99;
[self.view addSubview:splitVC.view];
之后,显示splitView
,但要摆脱它,我必须从视图中删除它,所以我创建了viewcontrollers
之间的通知。在主视图控制器中,我添加了观察者。 (注:主视图控制器不是splitViewController
或它的景色之一,它是加载splitViewController
视图控制器)中选择“removeSplitView
”我把我所有的当前视图的子视图的
NSNotificationCenter *splitViewObserver = [NSNotificationCenter defaultCenter];
[splitViewObserver addObserver:self selector:@selector(removeSplitView) name:@"removeSplitView" object:nil];
通过for循环并使用标签99搜索UIView类对象并将其从超级视图中移除。
NSArray *subviews = [self.view subviews];
for (int i = 0; i < [subviews count]; i++) {
if ([[subviews objectAtIndex:i] isKindOfClass:[UIView class]]) {
UIView *tempView = [subviews objectAtIndex:i];
if (tempView.tag == 99) {
[[subviews objectAtIndex:i] removeFromSuperview];
}
}
}
在的firstView我称做了方法的帖子,主要是ViewController
观察通知。
-(IBAction) done:(id)sender {
[fileSelectedNotification postNotificationName:@"removeSplitView" object:self];
}
您还必须在应用程序的某处创建fileSelectedNotification
。我通过viewDidLoad
做到了这一点。它看起来像这样。
fileSelectedNotification = [NSNotificationCenter defaultCenter];
当然我也添加了这个
NSNotiicationCenter *filesSelectedNotification;
这个viewController
的.h文件。
因此,当我按下完成按钮(这是我的应用程序栏按钮)时,它将从视图中删除splitViewController
。
工作正常。我从阅读文档中获得了所有这些。
您将得到一个未捕获的异常:“应用程序尝试以模态方式呈现分割视图控制器”[原文] – 2010-04-17 16:32:02