これは古い投稿ですが、別の方法で考えるのに役立つことがわかりました。これが問題の解決方法です。
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
またはそのビューの1つではなく、ロードするビューコントローラーですsplitViewController
)
NSNotificationCenter *splitViewObserver = [NSNotificationCenter defaultCenter];
[splitViewObserver addObserver:self selector:@selector(removeSplitView) name:@"removeSplitView" object:nil];
セレクター" removeSplitView
"で、現在のビューのすべてのサブビューを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には、メインが監視しているという通知を投稿するdoneというメソッドがありViewController
ます。
-(IBAction) done:(id)sender {
[fileSelectedNotification postNotificationName:@"removeSplitView" object:self];
}
fileSelectedNotification
また、アプリのどこかに作成する必要があります。私はこれを介して行いviewDidLoad
ました。こんな感じです。
fileSelectedNotification = [NSNotificationCenter defaultCenter];
もちろんこれも追加しました
NSNotiicationCenter *filesSelectedNotification;
この.hファイルにviewController
。
したがって、完了ボタン(アプリのバーボタン)を押すと、splitViewController
ビューから削除されます。
正常に動作します。私はドキュメントを読んだだけでこれをすべて手に入れました。