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

- (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中删除子视图?

谢谢。

最佳答案

尝试以下操作(假设您要删除第一个子视图):

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

关于cocoa - 如何从 cocoa 中的NSSplitView移除SubView?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3709364/

10-14 20:33
查看更多