0

Where is it proper to add an UIDatePicker? Should I add it in viewDidLoad? Or in loadView?

This UIDatePicker should be a subview of the main view, and will be displayed the entire time that this viewController's view is displayed.

Thank you!

joshim5
  • 2,292
  • 4
  • 28
  • 40

1 Answers1

0

It depends on whether you are loading your view from a nib or programmatically.

If you are loading from a nib, you want to use viewDidLoad.

If you are loading programmatically, you can use either, but to keep all of your view loading logic in one method, you should use loadView.

Scott Rice
  • 1,165
  • 1
  • 10
  • 16
  • My personal preference is to use viewDidLoad in all cases as that allows me to switch over from or to nibs at any time without any hassle. – Till May 25 '11 at 16:48
  • My personal preference for subclasses is to create a method called `setup_`. I then call this method from within `init` and within `awakeFromNib`. This keeps everything together and works for any classes loaded from a nib or programmatically. – mackross May 25 '11 at 16:59
  • Note however that if you require everything all nib connections to be made `awakeFromNib` doesn't guarantee that. In which case you should override `viewDidLoad` or `loadView`. – mackross May 25 '11 at 17:02
  • Thanks. None of my view logic will be done in IB. Everything will be loaded programatically. It looks like I'll use loadview – joshim5 May 25 '11 at 19:00