changing sub views in the split view

Discussion in 'Mac Programming' started by Chirone, Apr 20, 2009.

  1. Chirone macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #1
    hi all,

    i have four custom views i want to display but i only ever want to display three of them at the same time in a split view (and i learned that we can't display the same view twice... go figure)

    what i did was i made a horizontal pane with three scroll panes inside. After playing around with the measurements i got the pane view to resize everything properly so that nothing would become distorted and still fill the whole pane in the split view

    i had to make a class for the three custom views inside the scroll panes and all they do is make sure they flip so that the scroll pane starts at the top
    and they have the ability to change their subview (because the scrollpane wont let me change it's subview, it gives runtime errors)

    when the main program calls awakeFromNib it assigns one of the four custom views as a subview of the custom view inside the scroll pane
    at this point there is a lot of distortion and squashing of the four custom views
    not only that but the four custom views stay the same width and height when the window is resized (even though it was set to take up all the space in IB?)
    and when the method is called to change the subviews the four custom views are the correct size (but they still don't take up the space they are meant to)


    i'm fairly certian i'm doing EVERYTHING wrong because that's just mega-complicated

    and i think it's weird that calling this method:
    Code:
    - (void)changeSubView: (NSView*)newView {
    	NSArray* viewSet = [NSArray arrayWithObject: newView];
    	[self setSubviews: viewSet];
    	[self setBounds: [newView bounds]];
    	[self setFrame: [newView frame]];
    	[self setNeedsDisplay: YES];
    }
    from awakeFromNib results in squashed up subviews and then calling it again makes it show the subviews properly-ish


    surely changing the subviews of a scrollview isn't this complex....

    and just so you know setContentView also didn't work

    for some bizzare reason as soon as i hook a scrollview to a class the program instantly thinks its just a regular NSView even though the class inherits NSSrollView







    nevermind
    i think i found a suitable hax for it
    instead of trying to change the scroll view's custom view's subview (jezz, it still sounds overly complex for such a simple task)
    i'm changing the splitview's subviews
    and it seems i was able to guess the correct measurements to make a subview to appear correctly

    although it's very elegant having to make an array each time i want to change the views
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    setContentView: on a scroll view affects its clip view, which usually you don't want to change. You want instead setDocumentView:

    BTW if you're having trouble with NSSplitView I'd suggest using a third-party alternative RBSplitView. If you're doing complicated stuff with it this will help make things a lot easier.
     
  3. Chirone thread starter macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #3
    thanks

    i downloaded rbsplitview but wasn't sure how to add it to IB
    it's so different to the old version and none of the instructions for the old version applies to the current one
     

Share This Page