gpt4 book ai didi

objective-c - cocoa NSTableView 在 CustomView 中 SplitView 大小不调整

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

我有一个 NSSplitView 作为我的“ super View ”。在这个 SplitView 中是一个带有 NSTableView 的自定义 View 。我尝试从 Controller 类加载自定义 View ,然后调整自定义 View 和表的大小。但表格和/或自定义 View 的大小不会调整。我做错了什么?

这是我的 Controller 类方法,我在其中加载并设置自定义 View 的大小:
//头文件 @property (弱) IBOutlet NSView *navigationView; @property(强)AppsNavigationViewController *navigationViewController;

// Implementation
- (void) initNavigationView :(id)viewControllerClass :(NSString*) viewNibName {

_navigationViewController = [[viewControllerClass alloc]
initWithNibName:viewNibName bundle:nil];

// add the current custom view to the parent view
[_navigationView addSubview:[_navigationViewController view]];

[[_navigationViewController view] setAutoresizingMask:
NSViewHeightSizable|NSViewWidthSizable];

// set the bounds of the custom view to the size of the parent view
[[_navigationViewController view] setBounds:[_navigationView bounds]];

[_navigationViewController setDelegate:self]; // not relevant

[_splitView adjustSubviews]; // checked. contains the _navigationView

}

它的外观如下:

nssplitview with custom view and nstable

编辑我对一些 View 进行了子类化并绘制了不同的背景。这绝对是自定义 View 没有获得尺寸!

enter image description here

最佳答案

看起来您的表格框架可能不是其 super View 的起源。首先,尝试设置框架而不是边界,然后您可以调用它。

[[_navigationViewController view] setFrameOrigin:NSMakePoint(0,0)];

通常情况下,我通常会像这样设置框架/边界,因为您的 super View 的边界可能不在其 super View 的 {0,0} 处...

NSRect newFrame;
newFrame.origin.x = 0;
newFrame.origin.y = 0;
newFrame.size.width = [[someView superview] frame].size.width;
newFrame.size.height = [[someView superview] frame].size.height;
[someView setFrame:newFrame];

关于objective-c - cocoa NSTableView 在 CustomView 中 SplitView 大小不调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14387332/

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