Re: Getting IB_DESIGNABLE to work properly


Graham Cox
 

On 4 Mar 2018, at 4:14 pm, Quincey Morris <quinceymorris@rivergatesoftware.com> wrote:

AFAICT it doesn’t work like that. The canvas isn’t showing the view hierarchy, it’s showing the objects in the design hierarchy that you can reveal on the left. Of course, that represents the view hierarchy that will be created by nib loading, but that’s not happening at design/editing time.
Thanks for having a look,

I see what you’re saying, but IB has to instantiate the view (at least once) to capture what it renders. It must also redo this capture whenever any of the properties change. I can prove that by adding NSBeep() to the -drawRect method - it beeps on every property change. By the same approach I know that my subviews are created - but a beep in their -drawRect: method doesn’t occur.

If I have this code in my view’s -drawRect:, it also beeps:

if( self.subviews.count > 8 )
NSBeep();

This demonstrates that the subviews are there, so it’s not that IB is forcing the subviews to be empty after instantiating the view, it’s just somehow preventing them rendering - I wondered maybe by invoking -drawRect: instead of -display. I can’t think why they’d do this, it makes the feature a lot less useful than it could be. However, even if I call -display on all the subviews myself as part of -drawRect:, they don’t draw, so there’s something tricky going on.



I think your best choice is to eliminate the subviews, and do all the work in the parent view, using an internal “selected digit” mechanism. Your subviews aren’t so terribly complex that this is hard, just tedious.
Not worth the rewrite for this extra nicety, TBH.

—Graham

Join cocoa@apple-dev.groups.io to automatically receive all group messages.