Re: NSSplitView question - how to implement my own "adjustViews" style method

  • On Jul 3, 2012, at 01:46 , <cocoa-dev-request...> wrote:
    > Date: Tue, 03 Jul 2012 10:14:21 +1000
    > From: Graham Cox <graham.cox...>
    > Message-ID: <FC2C946D-C21D-4DD5-AA69-3756AADECD66...>
    >
    > On 03/07/2012, at 12:21 AM, Motti Shneor wrote:
    >
    >> I really need an advice here.
    >
    > This will sound flippant but it's not meant to be: implement your own split view.

    RBSplitView will do exactly what you want. However, unfortunately it's stuck in the times when IB was a separate app with plugins. If you can manage to set up your views in code (at least the split view and its subviews, then pull in the rest), it still seems to work well.

    If you want to roll your own, my advice would be to at least glance at the RBSplitView code (and docs) beforehand. Looking back, the crucial decision seems to have been to implement RBSplitSubviews to handle most of the work.

    Good luck, ;-)
    --
    Rainer Brockerhoff  <rainer...>
    Belo Horizonte, Brazil
    "In the affairs of others even fools are wise
    In their own business even sages err."
    Weblog: http://www.brockerhoff.net/blog
  • I haven't used RBSplitView, but it sounds like it might be handy to have a method for replacing an already-set-up NSSplitView with an RBSplitView. Maybe it could be a category method on NSSplitView, something like this:

    - (RBSplitView *)replaceWithRBSplitView
    {
    // Retain and autorelease self, to avoid premature dealloc.

    // Create an RBSplitView instance with the same frame as self.

    // Move self's subviews to the RBSplitView, preserving their frames.
    // I'm not sure if simply sending addSubview: to the RBSplitView works,
    // or if you have to explicitly remove the subviews from the NSSplitView.
    // To be safe I'd assume the latter, and again be careful about
    // premature dealloc.

    // Set the RBSplitView's delegate to self's delegate.

    // Send replaceSubview:with: to [self superview].

    // Return the RBSplitView.
    }

    This way you can still use IB to lay out the subviews of the split view, using a regular NSSplitView. In awakeFromNib, you can swap out the split view by calling this method.

    I think I'd try this approach if I was in a similar situation.

    --Andy

    On Jul 3, 2012, at 7:21 AM, Rainer Brockerhoff wrote:

    >
    > On Jul 3, 2012, at 01:46 , <cocoa-dev-request...> wrote:
    >> Date: Tue, 03 Jul 2012 10:14:21 +1000
    >> From: Graham Cox <graham.cox...>
    >> Message-ID: <FC2C946D-C21D-4DD5-AA69-3756AADECD66...>
    >>
    >> On 03/07/2012, at 12:21 AM, Motti Shneor wrote:
    >>
    >>> I really need an advice here.
    >>
    >> This will sound flippant but it's not meant to be: implement your own split view.
    >
    > RBSplitView will do exactly what you want. However, unfortunately it's stuck in the times when IB was a separate app with plugins. If you can manage to set up your views in code (at least the split view and its subviews, then pull in the rest), it still seems to work well.
    >
    > If you want to roll your own, my advice would be to at least glance at the RBSplitView code (and docs) beforehand. Looking back, the crucial decision seems to have been to implement RBSplitSubviews to handle most of the work.
    >
    > Good luck, ;-)
    > --
    > Rainer Brockerhoff  <rainer...>
    > Belo Horizonte, Brazil
    > "In the affairs of others even fools are wise
    > In their own business even sages err."
    > Weblog: http://www.brockerhoff.net/blog
  • On Jul 3, 2012, at 11:03 , Andy Lee wrote:

    > I haven't used RBSplitView, but it sounds like it might be handy to have a method for replacing an already-set-up NSSplitView with an RBSplitView. Maybe it could be a category method on NSSplitView, something like this:
    > ...
    > This way you can still use IB to lay out the subviews of the split view, using a regular NSSplitView. In awakeFromNib, you can swap out the split view by calling this method.

    Now that's an interesting idea, thanks Andy! I'll look into it soon, I hope.

    Handiest way might be to implement something like +[RBSplitView transmogrify:(NSSplitView*)someSplitView].

    All the cool extra RBSplitSubview properties would, of course, have to set manually... hm.
    --
    Rainer Brockerhoff  <rainer...>
    Belo Horizonte, Brazil
    "In the affairs of others even fools are wise
    In their own business even sages err."
    Weblog: http://www.brockerhoff.net/blog
  • On Jul 3, 2012, at 10:31 AM, Rainer Brockerhoff wrote:
    > On Jul 3, 2012, at 11:03 , Andy Lee wrote:
    >
    >> I haven't used RBSplitView, but it sounds like it might be handy to have a method for replacing an already-set-up NSSplitView with an RBSplitView. Maybe it could be a category method on NSSplitView, something like this:
    >> ...
    >> This way you can still use IB to lay out the subviews of the split view, using a regular NSSplitView. In awakeFromNib, you can swap out the split view by calling this method.
    >
    >
    > Now that's an interesting idea, thanks Andy! I'll look into it soon, I hope.
    >
    > Handiest way might be to implement something like +[RBSplitView transmogrify:(NSSplitView*)someSplitView].

    Nice -- that's a better API than my idea.

    I was about to add a P.S. that since your dividers might not be the same thickness as the dividers in the NSSplitView, there might have to be a bit of pixel tweaking. Maybe the docs for the method could advise using a particular divider thickness for best results, and/or the method could write a log message whenever it has to tweak pixels so that the subviews aren't *exactly* the same size as they were in the nib.

    --Andy

    >
    > All the cool extra RBSplitSubview properties would, of course, have to set manually... hm.
    > --
    > Rainer Brockerhoff  <rainer...>
    > Belo Horizonte, Brazil
    > "In the affairs of others even fools are wise
    > In their own business even sages err."
    > Weblog: http://www.brockerhoff.net/blog
    >
  • On Jul 3, 2012, at 10:31 AM, Rainer Brockerhoff wrote:

    >
    > On Jul 3, 2012, at 11:03 , Andy Lee wrote:
    >
    >> I haven't used RBSplitView, but it sounds like it might be handy to have a method for replacing an already-set-up NSSplitView with an RBSplitView. Maybe it could be a category method on NSSplitView, something like this:
    >> ...
    >> This way you can still use IB to lay out the subviews of the split view, using a regular NSSplitView. In awakeFromNib, you can swap out the split view by calling this method.
    >
    >
    > Now that's an interesting idea, thanks Andy! I'll look into it soon, I hope.

    P.P.S. I'm not sure how to deal with autolayout constraints that might get broken. Does replaceSubview:with: transfer constraints that were on the old view to the new view? (It would have to do some behind-the-scenes trickery, since NSLayoutConstraint is immutable.)

    What about the constraints on views within the subview panes? You *might* be okay there if all relevant constraints are contained in those views, but what if they're not? What if there's a constraint connecting a button inside one of the panes to a button outside of the split view entirely?

    Might not be a problem in practice. The worst case might be that on rare occasions, the programmer will have to patch some broken constraints after calling +transmogrify:.

    --Andy
  • On Jul 3, 2012, at 12:11 , Andy Lee wrote:
    > On Jul 3, 2012, at 10:31 AM, Rainer Brockerhoff wrote:
    >> Now that's an interesting idea, thanks Andy! I'll look into it soon, I hope.
    >
    > P.P.S. I'm not sure how to deal with autolayout constraints that might get broken. Does replaceSubview:with: transfer constraints that were on the old view to the new view? (It would have to do some behind-the-scenes trickery, since NSLayoutConstraint is immutable.)

    Well, RBSplitView was written way before autolayout and ARC, so I'm sure supporting either or both will need a complete rewrite...
    --
    Rainer Brockerhoff  <rainer...>
    Belo Horizonte, Brazil
    "In the affairs of others even fools are wise
    In their own business even sages err."
    Weblog: http://www.brockerhoff.net/blog
previous month july 2012 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today