Multiple UICollectionViews in ViewController | Would not call one CollectionViews Delegate methods












0














SO I have two UICollectionViews in my UIViewController in Storyboard and both are linked with delegate and datasource to my ViewController. All the associated UICollectionView delegate methods are implemented and checks for the UICollectionViews are implemented. But it's so frustrating that one UICollectionView is getting catered while the other one is getting completely ignored. I have scratched my head in all the available aspects but it is kind of putting me further towards the edge, please help.



func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if collectionView == self.variantsCollectionView {
// let count = (item?.variant_groups?.count)!
return 1
} else {
return 2//(item?.extra_groups?.count)!
}
}


and



func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{

if collectionView == self.variantsCollectionView {
//IT DOESNT EVEN COME HERE AT ALL
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell_variant", for: indexPath)
return cell

} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
//HERE IT COMES ALWAYS FOR THE NUMBER OF CELLS

return cell
}

}


Whereas the UICollectionViews are connected like this:
enter image description here



and:
enter image description here



Please please help. Thank you so much










share|improve this question






















  • Remove the delegate connection for the working collection view and check if data source methods are executed for the variantsCollectionView at all.
    – Evgeniy
    Nov 23 '18 at 13:36












  • If they do, then if collectionView == self.variantsCollectionView { not working. In that case, check if IBOutlet for variantsCollectionView is connected properly.
    – Evgeniy
    Nov 23 '18 at 13:38










  • @Evgeniy no they are not getting called for the working collection now neither are they working for the other one
    – Mohsin Khubaib Ahmed
    Nov 23 '18 at 13:39










  • Check in viewDidLoad() that collection's dataSource is not nil.
    – Evgeniy
    Nov 23 '18 at 13:42






  • 1




    Then check the cellSizeForItem, it must be 0,0 somehow.
    – Evgeniy
    Nov 23 '18 at 13:51
















0














SO I have two UICollectionViews in my UIViewController in Storyboard and both are linked with delegate and datasource to my ViewController. All the associated UICollectionView delegate methods are implemented and checks for the UICollectionViews are implemented. But it's so frustrating that one UICollectionView is getting catered while the other one is getting completely ignored. I have scratched my head in all the available aspects but it is kind of putting me further towards the edge, please help.



func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if collectionView == self.variantsCollectionView {
// let count = (item?.variant_groups?.count)!
return 1
} else {
return 2//(item?.extra_groups?.count)!
}
}


and



func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{

if collectionView == self.variantsCollectionView {
//IT DOESNT EVEN COME HERE AT ALL
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell_variant", for: indexPath)
return cell

} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
//HERE IT COMES ALWAYS FOR THE NUMBER OF CELLS

return cell
}

}


Whereas the UICollectionViews are connected like this:
enter image description here



and:
enter image description here



Please please help. Thank you so much










share|improve this question






















  • Remove the delegate connection for the working collection view and check if data source methods are executed for the variantsCollectionView at all.
    – Evgeniy
    Nov 23 '18 at 13:36












  • If they do, then if collectionView == self.variantsCollectionView { not working. In that case, check if IBOutlet for variantsCollectionView is connected properly.
    – Evgeniy
    Nov 23 '18 at 13:38










  • @Evgeniy no they are not getting called for the working collection now neither are they working for the other one
    – Mohsin Khubaib Ahmed
    Nov 23 '18 at 13:39










  • Check in viewDidLoad() that collection's dataSource is not nil.
    – Evgeniy
    Nov 23 '18 at 13:42






  • 1




    Then check the cellSizeForItem, it must be 0,0 somehow.
    – Evgeniy
    Nov 23 '18 at 13:51














0












0








0







SO I have two UICollectionViews in my UIViewController in Storyboard and both are linked with delegate and datasource to my ViewController. All the associated UICollectionView delegate methods are implemented and checks for the UICollectionViews are implemented. But it's so frustrating that one UICollectionView is getting catered while the other one is getting completely ignored. I have scratched my head in all the available aspects but it is kind of putting me further towards the edge, please help.



func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if collectionView == self.variantsCollectionView {
// let count = (item?.variant_groups?.count)!
return 1
} else {
return 2//(item?.extra_groups?.count)!
}
}


and



func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{

if collectionView == self.variantsCollectionView {
//IT DOESNT EVEN COME HERE AT ALL
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell_variant", for: indexPath)
return cell

} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
//HERE IT COMES ALWAYS FOR THE NUMBER OF CELLS

return cell
}

}


Whereas the UICollectionViews are connected like this:
enter image description here



and:
enter image description here



Please please help. Thank you so much










share|improve this question













SO I have two UICollectionViews in my UIViewController in Storyboard and both are linked with delegate and datasource to my ViewController. All the associated UICollectionView delegate methods are implemented and checks for the UICollectionViews are implemented. But it's so frustrating that one UICollectionView is getting catered while the other one is getting completely ignored. I have scratched my head in all the available aspects but it is kind of putting me further towards the edge, please help.



func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if collectionView == self.variantsCollectionView {
// let count = (item?.variant_groups?.count)!
return 1
} else {
return 2//(item?.extra_groups?.count)!
}
}


and



func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{

if collectionView == self.variantsCollectionView {
//IT DOESNT EVEN COME HERE AT ALL
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell_variant", for: indexPath)
return cell

} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
//HERE IT COMES ALWAYS FOR THE NUMBER OF CELLS

return cell
}

}


Whereas the UICollectionViews are connected like this:
enter image description here



and:
enter image description here



Please please help. Thank you so much







ios xcode uicollectionview storyboard swift4






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 13:34









Mohsin Khubaib Ahmed

7601322




7601322












  • Remove the delegate connection for the working collection view and check if data source methods are executed for the variantsCollectionView at all.
    – Evgeniy
    Nov 23 '18 at 13:36












  • If they do, then if collectionView == self.variantsCollectionView { not working. In that case, check if IBOutlet for variantsCollectionView is connected properly.
    – Evgeniy
    Nov 23 '18 at 13:38










  • @Evgeniy no they are not getting called for the working collection now neither are they working for the other one
    – Mohsin Khubaib Ahmed
    Nov 23 '18 at 13:39










  • Check in viewDidLoad() that collection's dataSource is not nil.
    – Evgeniy
    Nov 23 '18 at 13:42






  • 1




    Then check the cellSizeForItem, it must be 0,0 somehow.
    – Evgeniy
    Nov 23 '18 at 13:51


















  • Remove the delegate connection for the working collection view and check if data source methods are executed for the variantsCollectionView at all.
    – Evgeniy
    Nov 23 '18 at 13:36












  • If they do, then if collectionView == self.variantsCollectionView { not working. In that case, check if IBOutlet for variantsCollectionView is connected properly.
    – Evgeniy
    Nov 23 '18 at 13:38










  • @Evgeniy no they are not getting called for the working collection now neither are they working for the other one
    – Mohsin Khubaib Ahmed
    Nov 23 '18 at 13:39










  • Check in viewDidLoad() that collection's dataSource is not nil.
    – Evgeniy
    Nov 23 '18 at 13:42






  • 1




    Then check the cellSizeForItem, it must be 0,0 somehow.
    – Evgeniy
    Nov 23 '18 at 13:51
















Remove the delegate connection for the working collection view and check if data source methods are executed for the variantsCollectionView at all.
– Evgeniy
Nov 23 '18 at 13:36






Remove the delegate connection for the working collection view and check if data source methods are executed for the variantsCollectionView at all.
– Evgeniy
Nov 23 '18 at 13:36














If they do, then if collectionView == self.variantsCollectionView { not working. In that case, check if IBOutlet for variantsCollectionView is connected properly.
– Evgeniy
Nov 23 '18 at 13:38




If they do, then if collectionView == self.variantsCollectionView { not working. In that case, check if IBOutlet for variantsCollectionView is connected properly.
– Evgeniy
Nov 23 '18 at 13:38












@Evgeniy no they are not getting called for the working collection now neither are they working for the other one
– Mohsin Khubaib Ahmed
Nov 23 '18 at 13:39




@Evgeniy no they are not getting called for the working collection now neither are they working for the other one
– Mohsin Khubaib Ahmed
Nov 23 '18 at 13:39












Check in viewDidLoad() that collection's dataSource is not nil.
– Evgeniy
Nov 23 '18 at 13:42




Check in viewDidLoad() that collection's dataSource is not nil.
– Evgeniy
Nov 23 '18 at 13:42




1




1




Then check the cellSizeForItem, it must be 0,0 somehow.
– Evgeniy
Nov 23 '18 at 13:51




Then check the cellSizeForItem, it must be 0,0 somehow.
– Evgeniy
Nov 23 '18 at 13:51












1 Answer
1






active

oldest

votes


















1














Via comments the TS found solution by following these steps:




  1. Ensure both collection views have non-nil data sources (and delegates).

  2. Check that data source methods are executed for both collection view.

  3. Check that both collection views' cells have valid size.


Finally the problem was found after checking the heights of each collection view inside stack view.




basically CollectionView has a specific height whereas
VariantCollectionView didnt, and both were in a stackView. When first
was created in view it took up the entire size where as the other one
kind of actually disappeared. Hence the issue.







share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447698%2fmultiple-uicollectionviews-in-viewcontroller-would-not-call-one-collectionview%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Via comments the TS found solution by following these steps:




    1. Ensure both collection views have non-nil data sources (and delegates).

    2. Check that data source methods are executed for both collection view.

    3. Check that both collection views' cells have valid size.


    Finally the problem was found after checking the heights of each collection view inside stack view.




    basically CollectionView has a specific height whereas
    VariantCollectionView didnt, and both were in a stackView. When first
    was created in view it took up the entire size where as the other one
    kind of actually disappeared. Hence the issue.







    share|improve this answer


























      1














      Via comments the TS found solution by following these steps:




      1. Ensure both collection views have non-nil data sources (and delegates).

      2. Check that data source methods are executed for both collection view.

      3. Check that both collection views' cells have valid size.


      Finally the problem was found after checking the heights of each collection view inside stack view.




      basically CollectionView has a specific height whereas
      VariantCollectionView didnt, and both were in a stackView. When first
      was created in view it took up the entire size where as the other one
      kind of actually disappeared. Hence the issue.







      share|improve this answer
























        1












        1








        1






        Via comments the TS found solution by following these steps:




        1. Ensure both collection views have non-nil data sources (and delegates).

        2. Check that data source methods are executed for both collection view.

        3. Check that both collection views' cells have valid size.


        Finally the problem was found after checking the heights of each collection view inside stack view.




        basically CollectionView has a specific height whereas
        VariantCollectionView didnt, and both were in a stackView. When first
        was created in view it took up the entire size where as the other one
        kind of actually disappeared. Hence the issue.







        share|improve this answer












        Via comments the TS found solution by following these steps:




        1. Ensure both collection views have non-nil data sources (and delegates).

        2. Check that data source methods are executed for both collection view.

        3. Check that both collection views' cells have valid size.


        Finally the problem was found after checking the heights of each collection view inside stack view.




        basically CollectionView has a specific height whereas
        VariantCollectionView didnt, and both were in a stackView. When first
        was created in view it took up the entire size where as the other one
        kind of actually disappeared. Hence the issue.








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 14:09









        Evgeniy

        477413




        477413






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447698%2fmultiple-uicollectionviews-in-viewcontroller-would-not-call-one-collectionview%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)