I have an empty NSScrollView created with Interface Builder.
And in my code I add, upon a user click, a NSSegmentedControl. For all the next clicks, I add a segment to it.
My problem is that, once I reach the visual limit of NSScrollView, it doesn't start to scroll and all the post-limit segments are never shown.
This is the NSScrollView from Interface Builder :
And here is the method :
- (IBAction)addSegment:(id)sender
{
if (segCtrlColumns == nil) {
segCtrlColumns = [[NSSegmentedControl alloc] initWithFrame:[self.viewColumns frame]]; //self.viewColumns is the NSScrollView from IBOutlet
[segCtrlColumns setSegmentCount:1];
[segCtrlColumns setLabel:@"Test" forSegment:0];
[segCtrlColumns setTarget:self];
} else {
double increaseSegments = [segCtrlColumns segmentCount]+1;
[segCtrlColumns setSegmentCount:increaseSegments];
[segCtrlColumns setLabel:@"Test" forSegment:increaseSegments-1];
}
[self.viewColumns setDocumentView:segCtrlColumns];
}
And here is the problem :
(Well it is more likely "nothing to scroll" than "not scrollable")
Okay, I did a few tests and the problem is not the nsscrollview but the nssegmentedcontrol. It doesn't update its frame size at all. So it is stuck at the width I set in the
initWithFrame
- which was the size of the scrollView. (And this is why NSScrollView never started to scroll)I never found an easy way on how to get the real size (updated size) of NSSegmentedControl as more segments are added, so I did this trick :
here is the code :
The only problem here is that all the segments are at the same size and not dynamic...