In my cocoa program, I have drawn a NSScrollView in the nib. I want to programmatically add NSViews into this NSScrollViews so that users can scroll to see all the views even if some views are out of boundary.
Here is what I have done so far:
int startX = 23;
int startY = 157;
int verticalGap = 10;
for (int i = 0; i < 10; i++){
singleView *temp = [[singleDontKnowView alloc] init];
[temp setFrameOrigin:NSMakePoint(startX, startY + (temp.frame.size.height + verticalGap) * i)];
[_scorllView setDocumentView:temp];
}
The question is when I run this, it can only load one singleView at position (startX, startY). How to fix this so that all 10 singleViews will be displayed?
UPDATE:
So now my code looks like:
int startX = 23;
int startY = 157;
int verticalGap = 10;
NSView *docView = [[NSView alloc] initWithFrame:NSMakeRect(0,0,369,396)];
for (int i = 0; i < 10; i++){
singleView *temp = [[singleDontKnowView alloc] init];
[temp setFrameOrigin:NSMakePoint(startX, startY + (temp.frame.size.height + verticalGap) * i)];
[docView addSubView:temp];
}
[_scorllView setDocumentView: docView];
By running the code, I can only get an empty ScrollView.