2010-09-14 46 views
0

我加載這個IBActions如何從可可中的NSSplitView中刪除子視圖?

 

- (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之前刪除子視圖添加新的子視圖?

謝謝。

回答

4

試試這個(假設你要刪除的第一子視圖):

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