omgtheykilledkenny omgtheykilledkenny - 2 months ago 16
Swift Question

having issues scrolling to the end of NSScrollView programmatically

i have a

that every time i click a button , an object adds up in the scrollview , i added the code below , so each time i press the button and the object adds in the scrollview , my scrollview scrolls to the end of scroll view where the new object is added :

let widthcc = scollingView.documentView!.frame.size.width + 156
scollingView.contentView.scrollPoint( NSPoint ( x: widthcc, y: 0))

but i am not getting the result i want , whatever i do the new scrolling position in one object behind my actual last added object.

what am i doing wrong?

heres my xcode project :


Fast solution is this:

     @IBAction func myButtonAction(sender: AnyObject) {

    NSOperationQueue.mainQueue().addOperationWithBlock {[unowned self] in

        let widthcc = self.scollingView.documentView!.frame.size.width + 156
        self.scollingView.contentView.scrollPoint( NSPoint ( x: widthcc, y: 0))


It lets layout completing resizing you view and then scroll to the end in the cycle of UI loop.