问题
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:
Try this (assuming you want to remove the first subview):
[[[splitRightView subviews] objectAtIndex:0] removeFromSuperview];
来源:https://stackoverflow.com/questions/3709364/how-to-remove-a-subview-from-a-nssplitview-in-cocoa