0

I'm using iOS 6 with storyboard and ARC.

I've got on my storyboard a UIView that I want to use for positioning and sizing - I've created an IBOutlet for the control in my controller via the Ctrl drag/drop so I know it's connected.

Now I want to try to reference this UIView from within the controller so I can dynamically create subviews within that UIView, positioned appropriately.

I'm trying to access the UIView from within viewDidLoad as follows

CGRect rect = self.myView.frame;

...but the rect is always coming up as 0, 0, 0, 0. myView is defined in the header file as:

@property (weak, nonatomic) IBOutlet UIView *myView;

I thought that all the controls from the storyboard would already be initialized when you got to viewDidLoad. If this is not the case, where should I put the code to use the frame of the UIView to create my subViews?

Thanks in advance.

Ed Sinek
  • 4,829
  • 10
  • 53
  • 81
  • answered here: http://stackoverflow.com/questions/6757018/why-am-i-having-to-manually-set-my-views-frame-in-viewdidload – Ed Sinek Dec 19 '12 at 06:15
  • Except that answer is not totally valid for the case above. There's something other going on with view loading mechanism when using storyboards. If I make a new single view project using storyboard, place a subview onto the view and give it an outlet. Launch and observe the frame on viewLoad, viewWillAppear and viewDidAppear, it's only set on viewDidAppear. Doing this same without storyboard, it works as it is expected. – Yogi Apr 07 '13 at 10:44
  • 1
    There's a call `viewDidLayoutSubviews` which get's called after `viewWillAppear` and before `viewDidAppear`. That's the place to get reliably any subviews frame. – Yogi Apr 07 '13 at 11:02

0 Answers0