Re: layout method not getting called on Content View
Re: layout method not getting called on Content View
- Subject: Re: layout method not getting called on Content View
- From: Dave <email@hidden>
- Date: Thu, 16 Apr 2015 21:54:20 +0100
Hi Quincey,
> On 16 Apr 2015, at 20:42, Quincey Morris <email@hidden> wrote:
>
> On Apr 16, 2015, at 12:21 , Dave <email@hidden> wrote:
>>
>> On iOS, there is a method called “layoutSubviews” that I’ve used to do this sort of thing in the past, so it was deemed the correct place to do this in iOS, I assumed it would be the same or similar for Mac.
>
> No, it’s “old school” on the Mac.
>
>> I’m not sure where in the process to set the Frame, because if I do it just after the NIB is loaded it doesn’t seem to have any effect.
>
>
> If you’re talking about a window NIB, then you have to defer rearrangement of the window contents until the window loading process is fully complete. The easiest way is to set the subview frames in your window controller’s ‘windowDidLoad’ override.
Yes, this is a NIB that is owned by a WindowController and contains one Window. I override windowDidLoad and then call a method that recursively walks through the ContentView Hierarchy and sets the frame for each View. When I tried this before it didn’t seem to work. I’m really tired now, but will I straighten out the code and try it again in the morning. Now that I know it should work, I will again. I was playing around with different things while I was doing it and maybe I introduced a bug.
One detail is that the actual code that does this is in a Content View Subclass, So I call it like this:
[self.window.contentView setupLayout];
setupLayout then walks it’s subviews setting the frame for each View. Here is the windowDidLoad method:
-(void) windowDidLoad
{
LTWEchoWindow* myWindow;
LTWEchoContentView* myContentView;
myWindow = (LTWEchoWindow*) [self window];
myContentView = [myWindow contentView];
[myContentView setupLayoutWithConfigInfo:self.pContentConfigInfo];
[super windowDidLoad];
}
I’m wondering if the call to super should happen before I mess with the Content View?
> After that, you should be able to set the subview frames at any time.
Great!
> There are earlier possible points of intervention, but it’s tricky because you have to be certain that the outlets you’re using to get references to the subviews have be set up, and that nothing else is going to intervene and undo what you did. ‘windowDidLoad’ is the One, True™ ending point of the loading process, though, so it’s not worth making things any harder than that.
windowDidLoad is the perfect place for me to set the initial views, if that works then the notification part should work too, this is detected by the VC and passed down to the Content View which then updates the Subviews.
Thanks a lot for helping on this, I’ll pick it up again tomorrow. The demo is Monday but I might be able to push it back to Tuesday so I’ve got a couple of days to finish it off and once this is out of the way, there’s only one major thing left to do.
All the Best
Dave
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden