objective c - Container View Controller Programmatically -


i have been researching while can't quite find need. learn how create container view child view controller programmatically. i'm still new , learning basics, gather, used done using resuable views , attaching them child view controllers prior container view object being added library (right?), looking either tutorial or example code shows how scratch, using xib's, without complications, adding table cells etc... container , child programmatically. make sense? i'm sure there must on s.o. if can help.

update ---------------------------------------------------------------------------------------------------------------------- have managed create child view controller appears uibutton action. relevant code:

- (ibaction)pressed:(id)sender {     childviewcontroller *childviewcontroller = [[childviewcontroller alloc]init];     [self displaycontentcontroller:childviewcontroller]; }  - (void) displaycontentcontroller: (uiviewcontroller*) content {     [self addchildviewcontroller:content];     content.view.frame = cgrectmake(0, 115, 320, 240);     content.view.backgroundcolor = [uicolor redcolor];          catransition *transition = [catransition animation]; transition.duration = 1; transition.type = kcatransitionpush; transition.subtype = kcatransitionfromleft; [transition settimingfunction:[camediatimingfunction functionwithname:kcamediatimingfunctioneaseineaseout]]; [content.view.layer addanimation:transition forkey:nil]; [self.view addsubview:content.view]; [content didmovetoparentviewcontroller:self]; } 

so that's working fine. click button , red square, child view controller, occupying small part of screen appears. know if best practice.

basically involves having 1 parent view controller who'll orchestrate appearance of child view controllers.

to honest, find apple docs quite complete on part.

quote same docs :

adding child view controller content

to incorporate child view controller content programmatically, create parent-child relationship between relevant view controllers doing following:

  1. call addchildviewcontroller: method of container view controller. method tells uikit container view controller managing view of child view controller.
  2. add child’s root view container’s view hierarchy. remember set size , position of child’s frame part of process.
  3. add constraints managing size , position of child’s root view.
  4. call didmovetoparentviewcontroller: method of child view controller.

codesample :

- (void) displaycontentcontroller: (uiviewcontroller*) content {    [self addchildviewcontroller:content];    content.view.frame = [self frameforcontentcontroller];    [self.view addsubview:self.currentclientview];    [content didmovetoparentviewcontroller:self]; } 

responding update best practices :

objc.io has pretty neat articles in regard.

for example, article talking view controller containment notes :

view controllers should reusable , self-contained entities.

child view controllers no exception rule of thumb. in order achieve this, parent view controller should concerned 2 tasks: laying out child view controller’s root view, , communicating child view controller through exposed api. should never modify child’s view tree or other internal state directly.

child view controllers should contain necessary logic manage view trees – don’t treat them dumb views. result in clearer separation of concerns , better reusability.

they talk transitions between view controllers while using pattern.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -