如何从可可中的NSSplitView删除SubView? [英] How to remove a SubView from a NSSplitView in cocoa?

查看:123
本文介绍了如何从可可中的NSSplitView删除SubView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

但是有了这段代码,我只是将子视图放在彼此前面的堆栈中 在添加新的子视图之前,如何从 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?

谢谢.

推荐答案

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

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

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

这篇关于如何从可可中的NSSplitView删除SubView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆