gpt4 book ai didi

cocoa - 如何从 cocoa 中的 NSSplitView 中删除 subview ?

转载 作者:行者123 更新时间:2023-12-03 16:53:17 27 4
gpt4 key购买 nike

我正在使用此 IBActions 加载两个不同的 View


- (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);
}

但通过这段代码,我只是将堆栈一中的 subview 放在彼此前面在添加新 subview 之前,如何从 splitRightView 中删除 subview ?

谢谢。

最佳答案

试试这个(假设您想删除第一个 subview ):

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

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com