如何从可可中的NSSplitView中删除SubView?

时间:2010-09-14 13:36:31

标签: cocoa subview nssplitview

我正在使用此IBActions加载两个不同的视图


- (IBAction)showFirstView:(id)sender{
    theDetailViewController = [DetailViewController new];
    [theDetailViewController initWithNibName:@"DetailView" bundle:nil];
    NSView *splitRightView = [[theSplitView subviews] objectAtIndex:1];
    NSView *aDetailView = [theDetailViewController view];
    [aDetailView setFrame:[splitRightView bounds]];
    [aDetailView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
    [splitRightView addSubview:aDetailView];
    NSLog(@"%@",(NSString *)splitRightView);
}
- (IBAction)showSecondView:(id)sender{
    theNewViewController = [NewViewController new];
    [theNewViewController initWithNibName:@"NewView" bundle:nil];
    NSView *splitRightView = [[theSplitView subviews] objectAtIndex:1];
    NSView *aDetailView = [theNewViewController view];
    [aDetailView setFrame:[splitRightView bounds]];
    [aDetailView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
    [splitRightView addSubview:aDetailView];
    NSLog(@"%@",(NSString *)splitRightView);
}

但是使用这段代码我只是将堆栈中的子视图放在彼此的前面 如何在添加新子视图之前从 splitRightView 中删除子视图?

感谢。

1 个答案:

答案 0 :(得分:5)

试试这个(假设您要删除第一个子视图):

[[[splitRightView subviews] objectAtIndex:0] removeFromSuperview];