How to remove a SubView from a NSSplitView in coco

2019-08-08 05:11发布

I'm loading two different views with this 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);
}

but with this code I'm just getting the subviews in stack one in front of each other how do i remove the subview from splitRightView before adding the new subview?

thanks.

1条回答
我只想做你的唯一
2楼-- · 2019-08-08 05:31

Try this (assuming you want to remove the first subview):

[[[splitRightView subviews] objectAtIndex:0] removeFromSuperview];
查看更多
登录 后发表回答