Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initialize view without known frame?

I'm building view without .xib file, just using loadView method. But in the point, when loadView is called, the frame of view is yet unknown. So, I use it just to build view hierarchy without concrete frames. (Than I update view's layout when it's frame is known.) The question is: should I use [[UIView alloc] init] or [[UIView alloc] initWithFrame:CGRectZero] or may be something else, to initialize view without known frame? Here is the code:

- (void)loadView
{
    UIView *containerView = [[UIView alloc] init];
    // or 
    // UIView *containerView = [[UIView alloc] initWithFrame:CGRectZero];
    // or something else?        

    // ...

    self.view = containerView;
    [containerView release];
}
like image 229
Anastasia Avatar asked Dec 11 '25 14:12

Anastasia


1 Answers

- (id)initWithFrame: is the designated initializer for UIView, so you should use that, with a zero-sized rect.

like image 58
trojanfoe Avatar answered Dec 14 '25 05:12

trojanfoe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!