Pull To Refresh Stack View











up vote
0
down vote

favorite
1












I want to implement a pull to refresh feature on my current UIViewController. I have 10 buttons - 5 rows of vertical stack views in one horizontal stack view to create a grid. I would like to be able to pull to refresh here to run a function and update the button labels. What are my options?



Storyboard Layout










share|improve this question






















  • can you show me your stackView code in your viewController? I just want to see how you hooked up the stackView
    – RX9
    2 days ago















up vote
0
down vote

favorite
1












I want to implement a pull to refresh feature on my current UIViewController. I have 10 buttons - 5 rows of vertical stack views in one horizontal stack view to create a grid. I would like to be able to pull to refresh here to run a function and update the button labels. What are my options?



Storyboard Layout










share|improve this question






















  • can you show me your stackView code in your viewController? I just want to see how you hooked up the stackView
    – RX9
    2 days ago













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





I want to implement a pull to refresh feature on my current UIViewController. I have 10 buttons - 5 rows of vertical stack views in one horizontal stack view to create a grid. I would like to be able to pull to refresh here to run a function and update the button labels. What are my options?



Storyboard Layout










share|improve this question













I want to implement a pull to refresh feature on my current UIViewController. I have 10 buttons - 5 rows of vertical stack views in one horizontal stack view to create a grid. I would like to be able to pull to refresh here to run a function and update the button labels. What are my options?



Storyboard Layout







swift






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









J Dub

3811




3811












  • can you show me your stackView code in your viewController? I just want to see how you hooked up the stackView
    – RX9
    2 days ago


















  • can you show me your stackView code in your viewController? I just want to see how you hooked up the stackView
    – RX9
    2 days ago
















can you show me your stackView code in your viewController? I just want to see how you hooked up the stackView
– RX9
2 days ago




can you show me your stackView code in your viewController? I just want to see how you hooked up the stackView
– RX9
2 days ago












3 Answers
3






active

oldest

votes

















up vote
0
down vote













You can't add a refresh control into a stack view for the purpose of refreshing the content.



The important thing here is you have to add the refresh control into a scroll view to let it be functional as expected:




UIRefreshControl



A standard control that can initiate the refreshing of a scroll view’s
contents.



UIRefreshControl




For this case I would encourage to let your grid to be as a UICollectionView instead of stack view.



In addition, What if you tried to add another button into the grid? the container view should be scrollable, which means that a collection view would more maintainable.





Furthermore, you might be able to get the leverage of the UICollectionViewController. Checking the following could be useful:




  • Is completely static UICollectionView possible?

  • How to create a static UICollectionView.

  • How to use pull to refresh in Swift?






share|improve this answer






























    up vote
    0
    down vote













    Your best option is to go with a UICollectionView. Create a custom cell to you desired needs. After that you can add a refresh controller:



    // Global variable
    let pullToRefreshData = UIRefreshControl()

    // Where you initialise the collectionView (eg. viewDidAppear())
    collectionView.refreshControl = pullToRefreshData
    pullToRefreshData.addTarget(self, action: #selector(refreshData), for: .valueChanged)

    // This will be called when you pull from top of the collectionView
    @objc func refreshData() {
    // Maybe you need to call a server API, stop the reloading animation when you have the data
    pullToRefreshData.endRefreshing()

    // Refresh the data from the collectionView
    collectionView.reloadData()
    }


    If you only need to use your implementation, maybe you can provide a context.






    share|improve this answer










    New contributor




    Deryck Lucian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.

























      up vote
      0
      down vote













      For this use case I'd suggest using UICollectionView, which has build in support for UIRefreshControl. But if your buttons are somewhat different or you want a bit easier and less robust solution, you could simply embed your UIStackView in UIScrollView and set it's refreshControl.



      See: https://developer.apple.com/documentation/uikit/uiscrollview/2127691-refreshcontrol






      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',
        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%2f53365860%2fpull-to-refresh-stack-view%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        0
        down vote













        You can't add a refresh control into a stack view for the purpose of refreshing the content.



        The important thing here is you have to add the refresh control into a scroll view to let it be functional as expected:




        UIRefreshControl



        A standard control that can initiate the refreshing of a scroll view’s
        contents.



        UIRefreshControl




        For this case I would encourage to let your grid to be as a UICollectionView instead of stack view.



        In addition, What if you tried to add another button into the grid? the container view should be scrollable, which means that a collection view would more maintainable.





        Furthermore, you might be able to get the leverage of the UICollectionViewController. Checking the following could be useful:




        • Is completely static UICollectionView possible?

        • How to create a static UICollectionView.

        • How to use pull to refresh in Swift?






        share|improve this answer



























          up vote
          0
          down vote













          You can't add a refresh control into a stack view for the purpose of refreshing the content.



          The important thing here is you have to add the refresh control into a scroll view to let it be functional as expected:




          UIRefreshControl



          A standard control that can initiate the refreshing of a scroll view’s
          contents.



          UIRefreshControl




          For this case I would encourage to let your grid to be as a UICollectionView instead of stack view.



          In addition, What if you tried to add another button into the grid? the container view should be scrollable, which means that a collection view would more maintainable.





          Furthermore, you might be able to get the leverage of the UICollectionViewController. Checking the following could be useful:




          • Is completely static UICollectionView possible?

          • How to create a static UICollectionView.

          • How to use pull to refresh in Swift?






          share|improve this answer

























            up vote
            0
            down vote










            up vote
            0
            down vote









            You can't add a refresh control into a stack view for the purpose of refreshing the content.



            The important thing here is you have to add the refresh control into a scroll view to let it be functional as expected:




            UIRefreshControl



            A standard control that can initiate the refreshing of a scroll view’s
            contents.



            UIRefreshControl




            For this case I would encourage to let your grid to be as a UICollectionView instead of stack view.



            In addition, What if you tried to add another button into the grid? the container view should be scrollable, which means that a collection view would more maintainable.





            Furthermore, you might be able to get the leverage of the UICollectionViewController. Checking the following could be useful:




            • Is completely static UICollectionView possible?

            • How to create a static UICollectionView.

            • How to use pull to refresh in Swift?






            share|improve this answer














            You can't add a refresh control into a stack view for the purpose of refreshing the content.



            The important thing here is you have to add the refresh control into a scroll view to let it be functional as expected:




            UIRefreshControl



            A standard control that can initiate the refreshing of a scroll view’s
            contents.



            UIRefreshControl




            For this case I would encourage to let your grid to be as a UICollectionView instead of stack view.



            In addition, What if you tried to add another button into the grid? the container view should be scrollable, which means that a collection view would more maintainable.





            Furthermore, you might be able to get the leverage of the UICollectionViewController. Checking the following could be useful:




            • Is completely static UICollectionView possible?

            • How to create a static UICollectionView.

            • How to use pull to refresh in Swift?







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 2 days ago

























            answered 2 days ago









            Ahmad F

            15.4k94079




            15.4k94079
























                up vote
                0
                down vote













                Your best option is to go with a UICollectionView. Create a custom cell to you desired needs. After that you can add a refresh controller:



                // Global variable
                let pullToRefreshData = UIRefreshControl()

                // Where you initialise the collectionView (eg. viewDidAppear())
                collectionView.refreshControl = pullToRefreshData
                pullToRefreshData.addTarget(self, action: #selector(refreshData), for: .valueChanged)

                // This will be called when you pull from top of the collectionView
                @objc func refreshData() {
                // Maybe you need to call a server API, stop the reloading animation when you have the data
                pullToRefreshData.endRefreshing()

                // Refresh the data from the collectionView
                collectionView.reloadData()
                }


                If you only need to use your implementation, maybe you can provide a context.






                share|improve this answer










                New contributor




                Deryck Lucian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






















                  up vote
                  0
                  down vote













                  Your best option is to go with a UICollectionView. Create a custom cell to you desired needs. After that you can add a refresh controller:



                  // Global variable
                  let pullToRefreshData = UIRefreshControl()

                  // Where you initialise the collectionView (eg. viewDidAppear())
                  collectionView.refreshControl = pullToRefreshData
                  pullToRefreshData.addTarget(self, action: #selector(refreshData), for: .valueChanged)

                  // This will be called when you pull from top of the collectionView
                  @objc func refreshData() {
                  // Maybe you need to call a server API, stop the reloading animation when you have the data
                  pullToRefreshData.endRefreshing()

                  // Refresh the data from the collectionView
                  collectionView.reloadData()
                  }


                  If you only need to use your implementation, maybe you can provide a context.






                  share|improve this answer










                  New contributor




                  Deryck Lucian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.




















                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Your best option is to go with a UICollectionView. Create a custom cell to you desired needs. After that you can add a refresh controller:



                    // Global variable
                    let pullToRefreshData = UIRefreshControl()

                    // Where you initialise the collectionView (eg. viewDidAppear())
                    collectionView.refreshControl = pullToRefreshData
                    pullToRefreshData.addTarget(self, action: #selector(refreshData), for: .valueChanged)

                    // This will be called when you pull from top of the collectionView
                    @objc func refreshData() {
                    // Maybe you need to call a server API, stop the reloading animation when you have the data
                    pullToRefreshData.endRefreshing()

                    // Refresh the data from the collectionView
                    collectionView.reloadData()
                    }


                    If you only need to use your implementation, maybe you can provide a context.






                    share|improve this answer










                    New contributor




                    Deryck Lucian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    Your best option is to go with a UICollectionView. Create a custom cell to you desired needs. After that you can add a refresh controller:



                    // Global variable
                    let pullToRefreshData = UIRefreshControl()

                    // Where you initialise the collectionView (eg. viewDidAppear())
                    collectionView.refreshControl = pullToRefreshData
                    pullToRefreshData.addTarget(self, action: #selector(refreshData), for: .valueChanged)

                    // This will be called when you pull from top of the collectionView
                    @objc func refreshData() {
                    // Maybe you need to call a server API, stop the reloading animation when you have the data
                    pullToRefreshData.endRefreshing()

                    // Refresh the data from the collectionView
                    collectionView.reloadData()
                    }


                    If you only need to use your implementation, maybe you can provide a context.







                    share|improve this answer










                    New contributor




                    Deryck Lucian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    share|improve this answer



                    share|improve this answer








                    edited 2 days ago









                    Ahmad F

                    15.4k94079




                    15.4k94079






                    New contributor




                    Deryck Lucian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    answered 2 days ago









                    Deryck Lucian

                    715




                    715




                    New contributor




                    Deryck Lucian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.





                    New contributor





                    Deryck Lucian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.






                    Deryck Lucian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.






















                        up vote
                        0
                        down vote













                        For this use case I'd suggest using UICollectionView, which has build in support for UIRefreshControl. But if your buttons are somewhat different or you want a bit easier and less robust solution, you could simply embed your UIStackView in UIScrollView and set it's refreshControl.



                        See: https://developer.apple.com/documentation/uikit/uiscrollview/2127691-refreshcontrol






                        share|improve this answer

























                          up vote
                          0
                          down vote













                          For this use case I'd suggest using UICollectionView, which has build in support for UIRefreshControl. But if your buttons are somewhat different or you want a bit easier and less robust solution, you could simply embed your UIStackView in UIScrollView and set it's refreshControl.



                          See: https://developer.apple.com/documentation/uikit/uiscrollview/2127691-refreshcontrol






                          share|improve this answer























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            For this use case I'd suggest using UICollectionView, which has build in support for UIRefreshControl. But if your buttons are somewhat different or you want a bit easier and less robust solution, you could simply embed your UIStackView in UIScrollView and set it's refreshControl.



                            See: https://developer.apple.com/documentation/uikit/uiscrollview/2127691-refreshcontrol






                            share|improve this answer












                            For this use case I'd suggest using UICollectionView, which has build in support for UIRefreshControl. But if your buttons are somewhat different or you want a bit easier and less robust solution, you could simply embed your UIStackView in UIScrollView and set it's refreshControl.



                            See: https://developer.apple.com/documentation/uikit/uiscrollview/2127691-refreshcontrol







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered yesterday









                            Radek

                            168




                            168






























                                 

                                draft saved


                                draft discarded



















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365860%2fpull-to-refresh-stack-view%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

                                404 Error Contact Form 7 ajax form submitting

                                How to know if a Active Directory user can login interactively

                                TypeError: fit_transform() missing 1 required positional argument: 'X'