How to Use Child ViewControllers (Container Views) in Swift - Programmatic & Storyboard

Поділитися
Вставка
  • Опубліковано 17 січ 2025

КОМЕНТАРІ • 169

  • @seanallen
    @seanallen  5 років тому

    Watch Next - iOS Take Home Project - Job Interview Practice - Free Preview - ua-cam.com/video/MSIe2y6Fee8/v-deo.html

  • @lukeroberts3235
    @lukeroberts3235 5 років тому +17

    Was always worried about child view controllers. Didn’t realise how easy they were! Will definitely use these for my next project. Thanks Sean :)

  • @danluba
    @danluba 4 роки тому +3

    I always look for Sean Allen videos first whenever I need those sweet iOS tips.

    • @seanallen
      @seanallen  4 роки тому

      Happy to help, Dan!

    • @KailashAnand06
      @KailashAnand06 4 роки тому

      I know right! Haha, the first video I think I saw from him was mapkit

  • @natelehoux7604
    @natelehoux7604 4 роки тому +2

    You just clarified both container views and segues for me in under ten minutes. Awesome!

  • @patchinator6
    @patchinator6 Рік тому +1

    You're the man, Sean! Thanks for this

  • @dimiutube
    @dimiutube 4 роки тому +1

    Very clear and easy to understand! Thanks for showing both ways of adding child viewcontrollers as I will need the programmatic way!

    • @seanallen
      @seanallen  4 роки тому +1

      Glad it was helpful!

  • @ozgurshow
    @ozgurshow 4 роки тому +2

    clearly see how you enjoying to teach coding. Thanks Sean.

    • @seanallen
      @seanallen  4 роки тому

      Thanks for the kinds words, Eric.

  • @johnryles65
    @johnryles65 5 років тому +6

    Segue enum is brilliant!

  • @Alana9374
    @Alana9374 4 роки тому +1

    Thanks soooo much for sharing CLEARLY unlike a lot of others before you.

    • @seanallen
      @seanallen  4 роки тому

      Thanks for the kind words, Rob!

  • @theafzalansari01
    @theafzalansari01 5 років тому +1

    Was searching this topic for next project and here Sean Make a video of it thanx Sean.

  • @JunaidKhan-ny8tu
    @JunaidKhan-ny8tu 5 років тому +3

    What a coincidence!!! I was searching for this topic since last night :) thanks for such awesome content

    • @seanallen
      @seanallen  5 років тому +2

      I knew you're looking for it. That's why I made it.

    • @JunaidKhan-ny8tu
      @JunaidKhan-ny8tu 5 років тому +2

      Sean Allen haha thanks super man 😍😍❤️

    • @mracipayam
      @mracipayam 5 років тому +1

      Sean was listening your phooonnee and looking for content :D

  • @kolyalibak725
    @kolyalibak725 4 роки тому +4

    Wow! Great video, thank you
    Maybe you could help me, how can I make this slide-up card (from first example)? Thank you)

  • @iliana_b
    @iliana_b 5 років тому +1

    excellent video. short and sweet! keep it coming Sean!

  • @rrakesh05
    @rrakesh05 4 роки тому

    very nice to see ChildViewController

  • @OnionKnight541
    @OnionKnight541 3 роки тому +1

    if the viewer listens to the details that are tucked into this video, they'll learn like 1-full-year of Swift programming. the completeness of concepts is appreciated. almost like Sean is reading my mind (and the questions in my mind).

    • @seanallen
      @seanallen  3 роки тому

      Thanks for the kind words, Anthony!

  • @JasonMitchellAZ
    @JasonMitchellAZ 5 років тому +2

    Great job covering both storyboard and programmatically in one video, Sean

  • @siddharthtiwari6292
    @siddharthtiwari6292 4 роки тому +1

    Thanks for this amazing tutorial

  • @jamesb1664
    @jamesb1664 5 років тому +3

    Can someone tell me the name of the slide up card (that only covers half the screen) at the start of the video? Twitter and instagram have recently implemented the same thing.

    • @anuroopkanayil5724
      @anuroopkanayil5724 5 років тому

      JB - i am also looking for the bottom slide up card.

    • @jamesb1664
      @jamesb1664 5 років тому +1

      Anuroop Kanayil twitter.com/lukew/status/1016388934933217282?s=21

    • @jamesb1664
      @jamesb1664 5 років тому +1

      Anuroop Kanayil you may find this thread interesting

    • @anuroopkanayil5724
      @anuroopkanayil5724 5 років тому

      Thanks 👌🏻

    • @jamesb1664
      @jamesb1664 5 років тому

      Anuroop Kanayil I ended up using the framework Material.io and using their version of a bottom sheet - it works very well

  • @RussellSivalingam
    @RussellSivalingam 5 років тому +1

    Sean, as usual, another brilliant tutorial. that Segues enum.. brilliant!!

    • @seanallen
      @seanallen  5 років тому +1

      Glad you liked it, Russell!

  • @_modiX
    @_modiX 3 роки тому +1

    You should include "Embedded Segues" into the title, because I wasn't aware those are only Child ViewControllers, but your video helped a lot, thank you. And a much bigger thanks for showing how to do it in code, this is what I needed.

  • @negar3950
    @negar3950 4 роки тому +1

    Great video! I really enjoy the way you code! very neat :)

    • @seanallen
      @seanallen  4 роки тому +1

      Thanks Negar. Happy to hear it 😀

  • @TheFirzoknadeem1
    @TheFirzoknadeem1 5 років тому +1

    How did you make that sliding window in your app? Do you have a tutorial on that? I've been trying to make a sliding view on a map view but it is not working for me. The sliding view completely covers the whole map view.

  • @marvinabarca6200
    @marvinabarca6200 4 роки тому

    @seanallen can you show another example of how to pass values to a child view container? for example I have a slider in main view and a label in a container view and I want to display the slider value in label that is in container view but the slider is in main view.

  • @rubenvasquez4095
    @rubenvasquez4095 2 роки тому

    Hi, do you have a video on how to make floating panels? :)

  • @mohammadsayed5645
    @mohammadsayed5645 5 років тому +1

    You are doing a great job. Keep it up

  • @pradeepkumar-tm5et
    @pradeepkumar-tm5et 4 роки тому

    Hi Sean hope you are doing good. Could you please tell me the api response format how that need to be in order to the data in charts.

  •  5 років тому +1

    Helpful as always, thanks!

  • @omarmhaimdat
    @omarmhaimdat 5 років тому +1

    Always great content, keep up buddy!

  • @gakkieNL
    @gakkieNL 5 років тому +1

    As always a great watch! Thanks and cheers!

  • @ajinkyasonar
    @ajinkyasonar 4 роки тому +1

    Hey Sean, how can we make the container view dynamic. In this video you have provided an height constraint but what if we need it’s height should be based on the child view controllers content size?

    • @glen6638
      @glen6638 2 роки тому

      Just add constraints between child vc’ view and it’s sub views in child view controller ,and make sure there are enough constraints in vertical orientation

  • @jmlp1327
    @jmlp1327 4 роки тому +1

    Thanks a lot 🤗🤗🤗

  • @AntonBrock
    @AntonBrock 5 років тому +1

    I just search best practices for pass data between two or more Vc and I fined it! Ty for video! But I want to know how to do something like your first view ( with graph) if you have video about it pls link it! Ty!

    • @seanallen
      @seanallen  5 років тому +1

      Glad you liked the video! For that chart I used a 3rd party library called "Charts". If you google "iOS Charts library" it should pop up.

    • @AntonBrock
      @AntonBrock 5 років тому +1

      @@seanallen Ty! It's help me

  • @JakeDev901
    @JakeDev901 4 роки тому

    Cool! So helpful, thanks

  • @njrom
    @njrom 5 років тому

    I had no idea that this existed, but man I need this so bad in my app. Thank you

    • @seanallen
      @seanallen  5 років тому

      Happy to help you discover this 😀

  • @mracipayam
    @mracipayam 5 років тому +1

    its very clear

    • @seanallen
      @seanallen  5 років тому

      Glad it was helpful!

  • @RatherBeCancelledThanHandled
    @RatherBeCancelledThanHandled 4 роки тому

    Is the slide up controller a card view controller ? Any videos you’d be able to recommenced on it ? Thanks for sharing this vid ; helpful.

    • @seanallen
      @seanallen  4 роки тому

      In this case, it's just a view.

  • @Hmmmmaahhhh
    @Hmmmmaahhhh 4 роки тому

    Great video! Question: when/where was the secondChildVC set to green (initially)? Thanks!

  • @jameskayihura1675
    @jameskayihura1675 5 років тому

    Sean, Thanks a lot. That's brilliant...

  • @Денис-ж3ф5р
    @Денис-ж3ф5р 3 роки тому

    good stuff man.

  • @azhmanadam7311
    @azhmanadam7311 4 роки тому

    Hey Sean thanks for this video. I was wonder if it's possible that you somehow upload the codes?(for all your tuts from now on...)

  • @darrengillman4001
    @darrengillman4001 5 років тому +1

    Nice concise explanation. What vid was the explanation of static properties on (and more importantly does it cover the when/why, as well as the how)?

    • @seanallen
      @seanallen  5 років тому

      It was 4 or 5 videos ago. But here's the link: ua-cam.com/video/s2E5hVxQAZQ/v-deo.html

    • @seanallen
      @seanallen  5 років тому

      And yes, I give real examples of when to use it.

  • @StateMachineJunkie
    @StateMachineJunkie 5 років тому +1

    What is the advantage of using enum Segues { ... } versus struct Segues { ... } ?

    • @seanallen
      @seanallen  5 років тому

      It's a minimal difference... and enum can be better because if it's a struct you could initialize an empty one and have a random object out there. Doing something like Colors() will initialize an empty struct. You can't do that with an enum. So an enum is a little better for safety reasons in that example.

    • @roman3249
      @roman3249 5 років тому

      Segues() not Colors(). Colors() is from another video))))​

  • @manuhh9340
    @manuhh9340 5 років тому +2

    Thank you Sean! Nice tutorial!! By the way, what chart library are you using?

    • @seanallen
      @seanallen  5 років тому +1

      It's a library called "Charts". Google "iOS Charts" and the repo should pop up

    • @manuhh9340
      @manuhh9340 5 років тому

      @@seanallen Thanks man! I'm using the same one, but your chart looks way cooler :D

  • @ZhouHaibo
    @ZhouHaibo 3 роки тому

    Thanks. But should we create a UIView as container view and add that childVC into this UIView? As two steps, I see a lot of examples add container view like this. What is different with adding childVC as containerView directly?

  • @erickramones2167
    @erickramones2167 5 років тому

    do you think it is best to have segues in a different file?

  • @smarter2610
    @smarter2610 4 роки тому

    If you wanna have clean architecture where to store such enum like "Segues"? What folder or so?

  • @majdifelah
    @majdifelah 4 роки тому

    Hello Sean please how to do the bottom menu card

    • @seanallen
      @seanallen  4 роки тому +1

      coming soon

    • @acmcj
      @acmcj 4 роки тому

      @@seanallen Did you ever end up doing this tutorial?

  • @DimitrisTheo
    @DimitrisTheo 5 років тому +1

    Nice Sean 🤙🏻

    • @seanallen
      @seanallen  5 років тому +1

      Glad you liked it!

    • @DimitrisTheo
      @DimitrisTheo 5 років тому

      Sean Allen Doing both is way better for understanding

    • @seanallen
      @seanallen  5 років тому +1

      I agree. Sometimes doing both in the same video can be too long tho. This time it was quick.

  • @umeshdavera5221
    @umeshdavera5221 4 роки тому

    Great video! please do tutorial on switching between multiple/different UIViewControllers within single containerView. thanks in advance!

  • @manikanthag1066
    @manikanthag1066 5 років тому

    Hi . It is good .please share how to add child view as hamburger menu as coustmized viewcontroller

  • @CodeWithDevZain
    @CodeWithDevZain 3 роки тому

    in your actual application how you managed swipe gestures on child view?

  • @xMhnd
    @xMhnd 5 років тому +1

    Great work Sean! This was much simpler than what i expected. Was the slide chart made by you or a3rd party library?

    • @seanallen
      @seanallen  5 років тому +2

      The card was made by me, the chart is a 3rd party library called "charts"

    • @FatmaMohamed-mm6zo
      @FatmaMohamed-mm6zo 4 роки тому

      @@seanallen hello, how did you implement the card with that style ?

  • @geoffbaker2554
    @geoffbaker2554 5 років тому

    Great video, thank you.
    Sean I am struggling with a container view that is embedded and always visible on a macOS app. I can’t pass and display data because it doesn’t ‘load’ again as it’s always visible. Any thoughts or videos that may help?

    • @seanallen
      @seanallen  5 років тому

      I've never built a macOS app, so I'm not sure I can be of help here. My apologies.

  • @BubbleBassBackShots
    @BubbleBassBackShots 5 років тому +1

    A question Sean (several actually ): Let's say i were to attach a button to initiate a segue from one view controller to another and wanted to pass data as well. If i were to use the override function "prepare", how would it work ? Would the override function execute independently of the button (like you said in the vid), or will it execute after the button is pressed to move to the other view controller. Does the button only act as the "presenter" for the next view controller ? Does the override function keeps on getting called whenever data is changed on the sending view controller?

  • @gekoskipatric
    @gekoskipatric 3 роки тому

    How do you re-use child view controller in a different parent view controller?

  • @smarter2610
    @smarter2610 5 років тому +1

    Sean do you use or did you use RxSwift? Is it necessarry for junior ios ?? To be honest for me it is really hard to learn it and probably I will resign of it and focus more on basics like mvvm.

    • @seanallen
      @seanallen  5 років тому

      I've never used it before. But it's not uncommon.

  • @guruitcompany
    @guruitcompany 5 років тому +1

    Wow! 🤔👍👍Thanks!

  • @alexanderwald2046
    @alexanderwald2046 2 роки тому

    @Sean Allen I did it exactly like you in code, and now my child view controllers do not receive any touch events. what could be wrong? child VCs are instantiated from .xibs, but added programmatically

  • @emiliop5849
    @emiliop5849 4 роки тому

    Great video Sean. I have a question, in your introduction you show an app where a child view appear from the bottom, you created that effect changing the bottom constraint value while tapping the child view?

    • @jpcncaralho
      @jpcncaralho 4 роки тому

      Yes. Thank you for the video but when I see an example in the first part of the video, I would like to see the very same example in the tutorial. I wanted the slide up function, but I spent 10 minutes and there was no explanation about this. Waste of time. You make great videos, but pay attention to this, please...

  • @willasaskara
    @willasaskara 4 роки тому

    so, when we use self.addChild or self.present?

  • @andybevis1386
    @andybevis1386 4 роки тому

    Hi Sean, good video , nice and straightforward. However, when I load a VC as a child, if that Child VC then programmatically changes the text in a label , I get a found nil while unwrapping an optional. The label is declared as an IBOutlet in the code. Hoping you can help.

  • @synagridas13
    @synagridas13 5 років тому +2

    Excellent explanation as always. 1 question: when & why to use child View Controller, instead of just a subview(Ie a child UIView) ? Thank you 🙏

    • @seanallen
      @seanallen  5 років тому +2

      John Sundell explains that very well at the bottom of his article here. I'm too lazy to type it all out, lol: www.swiftbysundell.com/basics/child-view-controllers/

    • @synagridas13
      @synagridas13 5 років тому

      Great - thank you! Will read it :)

  • @TheAhmadReza
    @TheAhmadReza 5 років тому

    Where should we setup child view subviews!? (within ViewController or SecondChildVC)

  • @w0mblemania
    @w0mblemania 5 років тому +1

    Good tutorial, Sean. Thanks!
    Question: your charts look very good. Which charting framework are you using? Or Macaw, or rolling your own?

    • @seanallen
      @seanallen  5 років тому

      This one was built using "Charts". Google iOS Charts, and you should find the repo. It was built before I heard of Macaw.

    • @w0mblemania
      @w0mblemania 5 років тому +1

      @@seanallen Thanks Sean.

  • @brandonb6175
    @brandonb6175 5 років тому

    Hey Sean, any SDK recommendations for charting, great video btw!

  • @kelvinfok
    @kelvinfok 5 років тому +2

    Hi buddy, great tutorial. Will be good if the text is bigger cus I’m viewing from mobile :)

    • @seanallen
      @seanallen  5 років тому

      Thanks for the feedback. I'll keep it in mind. It's already really big on my screen. Much bigger and the line wrapping on all the code will start to look really bad.

  • @baralr-jay7729
    @baralr-jay7729 Рік тому +1

    Thanks broooooooo

  • @scottwang293
    @scottwang293 4 роки тому

    Hey Shawn, is it possible to add constraints to secondChildVC?
    Suppose it has to display some text inside. Every time I try to add a constraint within secondChildVC, xcode yells at em that it cant satisfy all constraints.

  • @brunoandrade8492
    @brunoandrade8492 5 років тому +1

    How can I make these dashed lines connecting the meteors/planets using SpriteKit?

    • @seanallen
      @seanallen  5 років тому

      In the case of this app... it’s an image. However you could draw a UIBezierPath with a gradient full I guess.

  • @Neil_Bergenroth_Rowing_Coach
    @Neil_Bergenroth_Rowing_Coach 4 роки тому

    Great video. Two questions 1) what charting library do you use in the first app shown? 2) how do you record your videos? I like that you are in the front with the background the desktop.

    • @seanallen
      @seanallen  4 роки тому +1

      Thanks Neil. It's a library called "charts". If you google iOS Chart library, it should be one of the first results. I record my face with a regular camera (with a greenscreen), my voice with a Blue Yeti mic and QuickTime, and I record my screen with QuickTime. Then I edit it all together in Final Cut Pro.

    • @Neil_Bergenroth_Rowing_Coach
      @Neil_Bergenroth_Rowing_Coach 4 роки тому

      Sean Allen thanks for your reply. Much appreciated, I’ll follow your channel now.

    • @seanallen
      @seanallen  4 роки тому

      Thanks for the support 😀

  • @Monarch_943
    @Monarch_943 5 років тому

    Hey Al, I'm trying to create an app with a navigation drawer, basically one parent viewController that has the drawer and handles switching view controllers in the container view. Is this a good approach?

  • @afeefsohail4869
    @afeefsohail4869 5 років тому

    Please any one can tell me how to create expandable ViewController on parent ViewController like he showed chart ViewController on parent ViewController in start of the video.

  • @tak68tak
    @tak68tak 4 роки тому +1

    Cool!

  • @katerinasmoliy2651
    @katerinasmoliy2651 3 роки тому

    So dope!! :)

  • @thejask2765
    @thejask2765 3 роки тому

    can we have some flutter videos. How to do iOS apps/ widgets in flutter?

  • @perfecttime949
    @perfecttime949 4 роки тому

    So child view controllers cant share a class with the main view controller.

  • @esc4p3EP
    @esc4p3EP 5 років тому

    Terbaik lah botak!

  • @josephbryant1917
    @josephbryant1917 4 роки тому

    Can someone help me to change my Xcode color to red as seen in this video?

    • @seanallen
      @seanallen  4 роки тому +1

      It's in your General Mac settings, not Xcode. You can choose your accent color.

    • @josephbryant1917
      @josephbryant1917 4 роки тому

      @@seanallen Thank you so much. I thought it was an Xcode specific setting.

  • @AliAljoubory
    @AliAljoubory 5 років тому

    Always great timing with your videos man. Been using childVc's on a project at work through Storyboards, but the 1 thing I was stuck on was being able to control when the childVc was initialised through the segue. It seems that the segue is always performed at viewDidLoad in the parentVc, no matter where else I tried calling performSegue. I basically wanted to initialise the view after making an API call on the parentVc, but that never could work out.
    Is there an actual way to control when the childVc is created or will that always be when the parentVc loads?
    Thanks for the video again man.

    • @eric9964
      @eric9964 4 роки тому

      Late response, but did you try using childvc’s programmatically? That way you’re able to determine when exactly they are created.

  • @TranHoang-up9mb
    @TranHoang-up9mb 5 років тому +5

    We use container view to avoid “massive view controller”, right ?

  • @fernandoluis53
    @fernandoluis53 4 роки тому

    You didn't show how to do the reverse. Get data from child to parent.

  • @vamsi3877
    @vamsi3877 5 років тому

    When to remove child ?

    • @freeme6111
      @freeme6111 5 років тому +2

      when it's 18 yrs old

    • @vamsi3877
      @vamsi3877 5 років тому

      @@freeme6111 😁

    • @saj5935
      @saj5935 5 років тому

      @@freeme6111 😂

  • @Денис-ж3ф5р
    @Денис-ж3ф5р 2 роки тому

    Who are those people using storyboards

  • @taylermoosa
    @taylermoosa 5 років тому

    So I'm taking someone's iOS Dev course (seanallen.teachable.com/) and the instructor over there sets his constraints with an array to avoid manually tacking on the isActive at the end of each. Any benefit to the more manual way shown here or is it really just down to preference?

    • @seanallen
      @seanallen  5 років тому

      This video using .isActive = true was before I knew that using the array for NSLayoutConstraints.activate is more efficient.

    • @taylermoosa
      @taylermoosa 5 років тому

      @@seanallen Gotcha. It's helpful to see not only the various ways you can accomplish the same task but also to see how your preferences change through these videos and in your course. It points to the fact that while optimization is important, what's MORE important is using the tools you have to solve the problem to yield the desired result.
      Love the videos on UA-cam for these one-off topics, but your course (65% through so far) is incredibly thorough, provides the 'why' behind a lot of stuff 'cut and paste coders' know to do but can't explain why, and definitely worthwhile for anyone interested in the field.

    • @seanallen
      @seanallen  5 років тому +1

      Thanks for the kind words on the course. Hopefully, as an engineer, you're constantly evolving and improving so your thoughts on certain topics and implementations will change over time.

  • @sova_oleksandr
    @sova_oleksandr 4 роки тому +2

    8:55 - Ukraine 🇺🇦

  • @Денис-ж3ф5р
    @Денис-ж3ф5р 3 роки тому

    the more I learn, the more I realize I know nothing, period

  • @k3mp3r111
    @k3mp3r111 5 років тому +6

    God bless Ukraine 🇺🇦
    (VC at the end of video lol)

    • @k3mp3r111
      @k3mp3r111 5 років тому

      "And there we go"

  • @djryanashton
    @djryanashton Рік тому

    I like your videos but this doesn't really match with the modal presentation example in the beginning. I'm wanting to present a 2nd VC modally with a few custom settings (such as the MainVC not shrinking in size) and also present only a 1/4 way up the screen. I'm sure you have a video that I could learn from ;)
    I found this (ua-cam.com/video/qiOKO8ta1n4/v-deo.html) which addresses both issues. Thanks Sean.

  • @ЯрославГрицунь
    @ЯрославГрицунь 5 років тому

    maybe coding isn't THAT scary after all...

  • @tenminutetokyo2643
    @tenminutetokyo2643 4 роки тому

    DOOD!

  • @Alexiy25raffasan
    @Alexiy25raffasan 3 роки тому +1

    Ukraine