This code works well:
UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:pickerFrame];
[pickerView addTarget:self
action:@selector(pickerChanged:)
forControlEvents:UIControlEventValueChanged];
[self.view addSubview:pickerView];
Why i don’t need to add pickers controller to my UIViewControllers hierarchy?
[self addChildViewController:pickerView.controller];
I know, UIView has no controller property. But how UIPIcker component adds his controller to controllers hierarchy? Or UIPicker have no controller at all? Or this controller don’t need to be in controllers hierarchy?
I need to know this to develop my own custom UI components, that should should be easy to integrate.
UIDatePickeris a subclass ofUIControlthat is a subclass ofUIViewSo its not a
UIViewController, addingUIViewto the views is adding usingaddSubViewIf
UIDatePickerwas a subclass ofUIViewControllerthen indeed you would have to add it usingaddChildViewControllerWhen you create your custom views its your coice, it will depend on what class you extend, if you extend
UIViewthen you will need to useaddSubView, if it will extendUIViewControllerthen useaddChildViewController