I'm trying to add multiple images of NSImageView to the NSScrollView. When I add it as a subview, the scrollview doesn't seem to scroll and when I add it as a document view I can see only one image. Any ideas or sample code on how to get this working? Suggestions pls. Thank you
1 Answers
0
votes
My best guess is that your framing is done wrong, or you forgot to set frame of the document view. Below is an example of adding stuff to the scroll view.
float allHeight = 0.f; // Consider starting from the top
float xOffset = 0.f; // Offset addjustments
float yOffset = 20.f;
float spacing = 5.f; // Spacing
float attachementCellHeight = 40.f;
// Values above are random :)
for (MyObject *obj in SetOfObjects) {
NSView *attachementView = [[[NSView alloc] initWithFrame:NSMakeRect(xOffset, allHeigth, self.bounds.size.width - xOffset, attachementCellHeight)] autorelease];
[self.documentView addSubview:attachementView];
allHeigth += attachementCellHeight;
allHeigth += spacing;
}
allHeigth+=yOffset;
self.documentView.frame = NSMakeRect(1, 1, self.bounds.size.width - 2, allHeigth);