0

I have a UIView/UIViewController (UIViewController) within storyboard that contains a custom UIView (CustomView) that has an associated .xib file. I am encountering the following phenomenon when I load UIViewController:

  • CustomView's awakeFromNib function is called
  • SOMETHING(?) sets my subview's frame to a height of 0.0; stack trace reveals [UIViewController autoresizedArchivedView] (relevant?)
  • UIViewController's viewDidLoad function is called

Any idea what this "something" that occurs between awakeFromNib and viewDidLoad and how I might control it?

Ken M. Haggerty
  • 24,902
  • 5
  • 28
  • 37
  • That "something" is most probably the autolayout. Try calling the `awakeFromNib` of your custom view in `-(void)viewDidLayoutSubviews` just to see if it works. – Eugene Mar 27 '13 at 01:47
  • @Eugene: To see if what works? Calling the custom view's `awakeFromNib` from within the view controller's `viewDidLayoutSubviews` does not seem to set the custom view back to its original height (as set from storyboard). – Ken M. Haggerty Mar 27 '13 at 02:08

1 Answers1

0

Geometric properties are not set on archived objects until after viewDidLoad:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        NSLog (@"%@ %@",
               NSStringFromSelector(_cmd),
               NSStringFromCGRect(self.testView.frame));

    }

    - (void) viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        NSLog (@"%@ %@",
               NSStringFromSelector(_cmd),
               NSStringFromCGRect(self.testView.frame));
    }


    - (void) viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
        NSLog (@"%@ %@",
               NSStringFromSelector(_cmd),
               NSStringFromCGRect(self.testView.frame));
    }

Log:

    viewDidLoad {{0, 0}, {0, 0}}
    viewWillAppear: {{0, 0}, {0, 0}}
    viewDidAppear: {{80, 224}, {160, 274}}
foundry
  • 31,615
  • 9
  • 90
  • 125
  • My log file shows: viewDidLoad {{0, 249}, {320, 0}}, viewWillAppear: {{0, 249}, {320, 0}}, viewDidAppear: {{0, 249}, {320, 0}}. The subview is a custom UIView with an associated .xib file. – Ken M. Haggerty Mar 28 '13 at 17:43