我创建了一个 NSScrollView 并在其中添加了自定义 NSVIew,但是在运行时,它始终在底部有一个空间,并且滚动条始终在底部。现在,我想滚动视图与自定义视图和滚动条始终位于顶部。这是我的代码:
float label_Y;
float textfield_Y;
float heightView;
-(void) createTableWiFi: (int) number
{
heightView = (25 + 30) * number;
guiView = [[NSView alloc] initWithFrame:NSMakeRect(0,0,600, heightView)];
label_Y = heightView;
textfield_Y = heightView ;
[[ScrollView verticalScroller] setFloatValue:0.0];
[[ScrollView contentView] scrollToPoint:NSMakePoint(0.0, heightView)];
int i;
for(i=1; i<=number;i++)
{
ssidtxt = [[NSTextField alloc] initWithFrame:NSMakeRect (50,textfield_Y,130,25)];
[ssidtxt setBezelStyle:NSTextFieldSquareBezel];
ssidtxt.tag=i;
[ssidtxt setAutoresizingMask:NSViewWidthSizable];
[guiView addSubview:ssidtxt];
[ssidtxt release];
keytxt = [[KSPasswordField alloc] initWithFrame:NSMakeRect (200,textfield_Y,130,25)];
[guiView addSubview:keytxt];
[keytxt release];
textfield_Y -=30;
}
prototype= [[NSButtonCell alloc] init];
[prototype setTitle:@""];
[prototype setButtonType:NSRadioButton];
NSRect matrixRect = NSMakeRect(500, textfield_Y +25 , 50,25 *(i-1));
myMatrix = [[NSMatrix alloc] initWithFrame:matrixRect
mode:NSRadioModeMatrix
prototype:(NSCell *)prototype
numberOfRows:i-1
numberOfColumns:1];
[myMatrix setCellSize:NSMakeSize(50, 30)];
[myMatrix setAction:@selector(radioButtonClicked:)];
NSArray *cellArray = [myMatrix cells];
[guiView addSubview:myMatrix];
[ScrollView setDocumentView :guiView];
[[ScrollView verticalScroller] setFloatValue:0.0];
[[ScrollView contentView] scrollToPoint:NSMakePoint(0.0, heightView)];
[guiView release];
}
欢迎任何建议。提前致谢