开发者

How to remove a SubView from a NSSplitView in cocoa?

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]];
    [aDetai开发者_JAVA百科lView 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.


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜