在SplitView大小的CustomView中的可可NSTableView不调整

时间:2013-01-17 20:12:58

标签: objective-c cocoa nstableview nsview nssplitview

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

这是我的控制器类方法,我加载并设置自定义视图的大小:
    //头文件     @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

修改 我将一些观点分类并绘制了不同的背景。而且它绝对是自定义视图,不能达到这个尺寸!

enter image description here

1 个答案:

答案 0 :(得分:1)

似乎你的桌子的框架不是它的超级视图的原点。首先,尝试设置框架而不是边界,然后在执行此操作后调用它。

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

通常情况下,我通常设置这样的帧/边界,因为你的超级视图的界限可能不在其超级视图的{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]; 
相关问题