iOS Dev 11: CollectionViews | Swift 5, XCode 11

Sdílet
Vložit
  • čas přidán 16. 07. 2024
  • In this lesson, we learn how to configure a UICollectionView.
    First, we add a UICollectionView to the ViewController in our Main.storyboard and connect it to our ViewController class.
    Next, we conform to the UICollectionViewDataSource protocol and implement two methods to specify the number of items in each section, and configure the cell for the item at index path.
    Afterwards, we learn how to create and set up a custom CollectionViewCell and add width and height.
    Finally, we learn how to handle Row Tap by conforming to the UICollectionViewDelegate protocol.
    Say Hi on Social Media:
    Project Link: github.com/EMacco/ios-tutoria...
    LinkedIn: / emacco
    Twitter: / its_macco
    If you feel like buying me a coffee :)
    www.buymeacoffee.com/emmanuel...
  • Věda a technologie

Komentáře • 89

  • @olajideosho9186
    @olajideosho9186 Před 3 lety +4

    The most straightforward CollectionView Tutorial on CZcams.

  • @waheedafolabi6929
    @waheedafolabi6929 Před 3 lety +1

    Needed a refresher and you just saved my life. Thanks Emmanuel!

  • @michelleweekes1514
    @michelleweekes1514 Před 2 lety

    Thank you so much! You saved me as I am creating a final project in school and needed to know how to do this!

  • @user-xc1yd4dx6x
    @user-xc1yd4dx6x Před 3 lety

    Thanks, Emmanuel! You helped me a lot to learn it.

  • @muzammalabdulghafoor6418

    Simple and great explanation

  • @buendiaoma
    @buendiaoma Před 2 lety

    Thanks buddy!!! I saw manny videos and this one is the best!!! Good job!!!

  • @yusufmd1090
    @yusufmd1090 Před 3 lety +2

    Your explanation is awesome bro.Thank you. Waiting for more videos.

  • @girishparate5899
    @girishparate5899 Před 2 lety

    I loved to see a video about reusable UIVIews like Button, Text, Input text 😇

  • @liveanimails
    @liveanimails Před 3 lety +1

    yes, it would be nice to have a video continuation so that the pictures are automatically adjusted to any screen and rotation

  • @alex741321
    @alex741321 Před 3 lety

    Great tutorial, thanks

  • @allin6074
    @allin6074 Před 2 lety

    thank you so much bro u saved me :)

  • @mahmutenescetin9235
    @mahmutenescetin9235 Před 2 lety

    thanks bro, this video fixed my problem

  • @nguyentienuc8578
    @nguyentienuc8578 Před 2 lety

    thanks you Emmanuel!

  • @tahasivrioglu9648
    @tahasivrioglu9648 Před 11 měsíci

    Thanks a lot

  • @Xunnun
    @Xunnun Před 3 lety

    Thanks For This Video

  • @YourLeader350
    @YourLeader350 Před 2 lety

    Thanks so much

  • @raychen4458
    @raychen4458 Před 2 lety

    Wanna see a more adaptable collection cell when it comes to different sizes, too !

  • @olenamakhobei1405
    @olenamakhobei1405 Před 2 lety

    Thank you a lot!

  • @Dissident.Dissidentovich

    Dear, thanks for programm realization! uzfl for commercial projects!

  • @jarmenkell5644
    @jarmenkell5644 Před rokem

    good job

  • @easthastings6919
    @easthastings6919 Před 3 lety

    quality content

  • @Kalash040
    @Kalash040 Před 2 měsíci

    Great!

  • @BestTutorialsLearning
    @BestTutorialsLearning Před 4 lety

    thanks

  • @user-yd9xy3rb4x
    @user-yd9xy3rb4x Před 2 lety

    good stuff

  • @rax7838
    @rax7838 Před 2 lety +1

    Your videos are so helpful. I feel like I found a gold mine. only problem is the font is too big so we can't see the all code. for some reason it is very exhausting to me. but still love your work. and how we can make cells responsible instead of giving fixed h and w

    • @EmmanuelOkwara
      @EmmanuelOkwara  Před 2 lety

      Thanks for the feedback. 😊
      I’ll try to work on the font and make it more accessible.

  • @JohnLiuFromHK
    @JohnLiuFromHK Před 2 lety

    Thank you, you explained very well in this video. As you said, I really want to know how to adapt better for different screen size, or customize more. Like setting the margin, padding or sth like that would help :)

    • @EmmanuelOkwara
      @EmmanuelOkwara  Před 2 lety

      I’ll definitely consider a more in-depth tutorial on this topic. 😊

  • @richardgomez9093
    @richardgomez9093 Před rokem

    hi thank for the video is there a way to put it horizontaly many thanks

    • @EmmanuelOkwara
      @EmmanuelOkwara  Před rokem

      You could either check the Yummie series on my channel or this video
      czcams.com/video/9Aoi-4sW6JU/video.html

  • @guruswriting
    @guruswriting Před 3 lety

    Thanks Emmanuel, can you do a video on passing data from collection view to detail view controller pls (so the tapped image displays)? Thanks

    • @EmmanuelOkwara
      @EmmanuelOkwara  Před 3 lety +1

      I actually did that in this video: czcams.com/video/Ud4zMWwyTwA/video.html
      Also, if you aren’t following the Yummie series, I’d advice you to take a moment and follow it. You’ll learn a whole lot 😊

    • @guruswriting
      @guruswriting Před 3 lety

      @@EmmanuelOkwara Thanks a lot Emmanuel for taking the time to reply, will checkout out right away, appreciate it!

  • @achintbhamra6701
    @achintbhamra6701 Před 2 lety +1

    kindly explain XIB file if you can !!

  • @muradanowar2618
    @muradanowar2618 Před 4 lety

    So Far Good

  • @vitorgomes4794
    @vitorgomes4794 Před 3 lety

    First of all, thanks for sharing this content Emmanuel. I would like to know if it is possible to explain about 15:11 when you said it is possible to make it more responsible. I am trying same things you did in the video but trying to adapt to different screen sizes

    • @EmmanuelOkwara
      @EmmanuelOkwara  Před 3 lety +2

      Thanks, Viktor.
      In this video, I returned a fixed size for each cell (200x300).
      When you run the app on smaller/larger screens, the cells will maintain the same dimension.
      A good way to make it more adaptive is to return a dynamic value for the width and height based on certain conditions.
      For example, we could set the cell's width to = (view.frame.size.width / 2) - (padding), this way, regardless of the screen size, there will always be 2 cells per row.
      In the same way, you can also calculate the height of the cell.

    • @vitorgomes4794
      @vitorgomes4794 Před 3 lety

      @@EmmanuelOkwara Thanks Emmanuel I also found almost the same answer as you provided. But how about the height when I am using a single cell? How can I make the height dynamic? I know that I need to calculate elements heights to give as a return of sizeForItemAt, but I don't know how to collect the size outside the extension. To be more clear, this is the result I trying to achieve: imgur.com/a/NggMTJ8

    • @vitorgomes4794
      @vitorgomes4794 Před 3 lety

      I tried this but did not worked, app crashes: On my CollectionViewCell file create the functions heightSum (factTextHeight: CGFloat, categoriesHeight: CGFloat) -> CGFloa and then made it return heightSum = lbFactsText.frame.height + lbCategories.frame.height. On my ViewController, specifically made on cellForIitemAt this: height = cell.heightSum(factTextHeight: cell.lbFactsText.frame.height, categoriesHeight: cell.lbCategories.frame.height) (where height is a global variable on ViewController), then, on CGSize(width: width - 40, height: sizeForItemAt is called before cellForItemAt method right?

  • @aksanazir753
    @aksanazir753 Před 3 lety +1

    Superb video.
    Can u plx tell me how can i go to other page in which detail about the movie is written by simply tapping on the inage or title. Plxxxx

    • @EmmanuelOkwara
      @EmmanuelOkwara  Před 3 lety +2

      At the point of this video, we know when a particular cell is tapped.
      The next thing we need to do is launch the new page that’ll display the information and send the movie at that index to the new view controller.
      We actually have that done in another series we’re currently working on. You can checkout this video....
      czcams.com/video/Ud4zMWwyTwA/video.html

    • @aksanazir753
      @aksanazir753 Před 2 lety

      @@EmmanuelOkwara sir can u plx tell me if i click on image i want to perform some action like print("abc") and when i click on the title i want to perform another action like print("123"). how can i do that. plx help

    • @EmmanuelOkwara
      @EmmanuelOkwara  Před 2 lety

      You can implement this by adding a tap feature recognizer to the image and label, then assign their actions to different methods.
      You can check this video to see how to add tap to a view.
      czcams.com/video/uFL0klyR7G0/video.html

  • @maryamnajafizada5729
    @maryamnajafizada5729 Před rokem

    Thank you so much. I just had a question, how to make the collection View cell to be clicked on like a button? If anyone else knows the answer to the question, I would very much appreciate it.

  • @BranGaming20
    @BranGaming20 Před 2 lety

    hello, i was following all your collectionview tutorial also using kingfisher, but how to play a video in cell? i want a cell fill by image or video randomly, please help me TIA

    • @EmmanuelOkwara
      @EmmanuelOkwara  Před 2 lety

      Unfortunately I haven’t made a video on AVPlayer yet but you could checkout this tutorial.
      www.raywenderlich.com/10857372-how-to-play-record-and-merge-videos-in-ios-and-swift

    • @BranGaming20
      @BranGaming20 Před 2 lety

      @@EmmanuelOkwara thanks for reply!

  • @shirakuyanai4095
    @shirakuyanai4095 Před 2 lety

    Hey what if I want to pick one of the images and make it appear on another collection view in other views?

    • @EmmanuelOkwara
      @EmmanuelOkwara  Před 2 lety

      In 13:35 you see how we can identify tap on a collectionviewcell.
      We can pass that data into the second view controller and populate your data source with it.

  • @EmreDurmus.
    @EmreDurmus. Před rokem

    although my code is the same, I get an error Unexpectedly found nil while implicitly unwrapping an Optional value how can I solve it

    • @EmmanuelOkwara
      @EmmanuelOkwara  Před rokem

      This means that the value of the property was not set. You may have to confirm from the video to see if you missed an assignment somewhere.

  • @jestinsaji8246
    @jestinsaji8246 Před 2 lety

    how to implement in such a way that when i make switch on from the main viewController the switch action have to be perfomed in another ViewController.

    • @EmmanuelOkwara
      @EmmanuelOkwara  Před 2 lety

      I believe I did something exactly similar in these videos:
      Observer: czcams.com/video/Ja1wPuaWyp4/video.html
      Delegates: czcams.com/video/HtU6yZbtCAQ/video.html

    • @jestinsaji8246
      @jestinsaji8246 Před 2 lety

      @@EmmanuelOkwara i want switch in only one page, when that switch is enabled then the next viewcontrollers color have to change

  • @amilzith5211
    @amilzith5211 Před 3 lety +1

    How to add image in the array

    • @EmmanuelOkwara
      @EmmanuelOkwara  Před 3 lety +4

      Hello, Amil
      I added the images to the array using Image Literal.
      You can bring up the Library by holding down COMMAND + Shift + L
      or
      You can type in #imageLiteral(resourceName: "image_name") and the string will be replaced with a thumbnail preview of the actual image.

  • @jestinsaji8246
    @jestinsaji8246 Před 2 lety

    how 2 create 2 segments such that segment 0 to display table view and segment 1 to display a collection view

    • @EmmanuelOkwara
      @EmmanuelOkwara  Před 2 lety +2

      Just like you’ve said, you could have a segmentView, a collectionview and a tableview in your UI.
      When the value of the segmentView changes, you check the selectedSegmentIndex property and set the isHidden property of both collectionView and tableView accordingly.

    • @jestinsaji9182
      @jestinsaji9182 Před 2 lety

      @@EmmanuelOkwara i have done but getting error can u make one

    • @EmmanuelOkwara
      @EmmanuelOkwara  Před 2 lety +1

      I created a sample app here. I hope it helps.
      github.com/EMacco/ios-tutorials/tree/segment-view

    • @jestinsaji8246
      @jestinsaji8246 Před 2 lety

      @@EmmanuelOkwara thanks a lot

  • @vivekbhadane1870
    @vivekbhadane1870 Před 3 lety

    can you help me for dynamic text. i achieve this layout but when i try to dynamic text but not working.

    • @EmmanuelOkwara
      @EmmanuelOkwara  Před 3 lety

      Dynamic cell height with a collection view is a little bit tricky. You’d need to calculate the intrinsic height of the labels content and set that as the height of the collection view.
      It’s easier if you’re using a table view.

    • @vivekbhadane1870
      @vivekbhadane1870 Před 3 lety

      @@EmmanuelOkwara sir i have same layout. Tableview view estimate size is good to handle automatically..can you help me with demo.

    • @vivekbhadane1870
      @vivekbhadane1870 Před 2 lety

      @@EmmanuelOkwara can you make one video for me.

  • @sindhurajan9097
    @sindhurajan9097 Před 2 lety

    How to use json parsing in collection view

    • @EmmanuelOkwara
      @EmmanuelOkwara  Před 2 lety

      I’m not sure I understand the question.
      Please could you explain?

    • @sindhurajan9097
      @sindhurajan9097 Před 2 lety

      @@EmmanuelOkwara nope ..I am clr and I did that 😁 thanks for ur reply..could you please tell me how to link tabbar programatically with the storyboard view controllers

  • @letskrishjourney
    @letskrishjourney Před 2 lety

    Pls upload mvvm using alamofire

    • @EmmanuelOkwara
      @EmmanuelOkwara  Před 2 lety

      I would love to but MVVM has no direct influence on your Network layer.
      You can just implement your network queries using Alamofire in the NetworkService class.

  • @RanjithKumar-sx2nv
    @RanjithKumar-sx2nv Před 3 lety

    Bro I'm not Abel to size it

  • @daxtech-pd3nr
    @daxtech-pd3nr Před 9 měsíci

    pl help anyone

  • @dwpalme2670
    @dwpalme2670 Před rokem

    You make the number of lines 0 and its dynamic.

  • @dwpalme2670
    @dwpalme2670 Před rokem

    That's stupid to set the width, you can make that dynamic dude to allow for scrolling.