Swift 4 Refresh Control not smooth but always jumpPassing Data between View ControllersHow do I call Objective-C code from Swift?#pragma mark in Swift?How to use pull to refresh in Swift?Split a String into an array in Swift?How to detect tableView cell touched or clicked in swiftuse javascript data in tableView SwiftUITableView using UIRefreshControl either Won't Finish or has Flicker/Jump under iOS11TableView and cells not visible on UIControllerView Swift 4Swift vertical UICollectionView inside UITableView

How use custom order in folder on Windows 7 and 10

What exactly did this mechanic sabotage on the American Airlines 737, and how dangerous was it?

Meaning of 'ran' in German?

Was there a trial by combat between a man and a dog in medieval France?

Strange Sticky Substance on Digital Camera

How can this Stack Exchange site have an animated favicon?

How do I deal with too many NPCs in my campaign?

Cut a cake into 3 equal portions with only a knife

What do you do if you have developments on your paper during the long peer review process?

What is the meaning of word 'crack' in chapter 33 of A Game of Thrones?

Resolving moral conflict

Is there a way to hide HTML source code yet keeping it effective?

Is this a Sherman, and if so what model?

Are there any adverse impacts if I keep WiFi router on all time?

Designing a time thief proof safe

Can I take NEW (still in their boxes) PC PARTS in my checked in luggage?

Late 1970's and 6502 chip facilities for operating systems

Does Fires of Invention allow adventure instant and sorceries to be played for free?

Is it impolite to ask for an in-flight catalogue with no intention of buying?

Is it really necessary to have a four hour meeting in Sprint planning?

What benefits does the Power Word Kill spell have?

Can the U.S. president make military decisions without consulting anyone?

How to manage expenditure when billing cycles and paycheck cycles are not aligned?

Is it right to extend flaps only in the white arc?



Swift 4 Refresh Control not smooth but always jump


Passing Data between View ControllersHow do I call Objective-C code from Swift?#pragma mark in Swift?How to use pull to refresh in Swift?Split a String into an array in Swift?How to detect tableView cell touched or clicked in swiftuse javascript data in tableView SwiftUITableView using UIRefreshControl either Won't Finish or has Flicker/Jump under iOS11TableView and cells not visible on UIControllerView Swift 4Swift vertical UICollectionView inside UITableView






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have a UIViewController, inside which there is a tableView. I added a RefreshControl. But when I pull, it always jumps for some times, which is not smooth and continuous at all.



I'm using Swift 4 and Xcode 10.1.



class ItemsController: UIViewController, UITableViewDelegate, UITableViewDataSource, UITextViewDelegate, ItemCellDelegate 
......
lazy var refreshControl: UIRefreshControl =
let refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action:
#selector(handleRefresh(_:)),
for: UIControl.Event.valueChanged)
refreshControl.tintColor = UIColor.lightGray

return refreshControl
()
......
override func viewDidLoad()
// Refresh
self.tableView.refreshControl = self.refreshControl

......
@objc func handleRefresh(_ refreshControl: UIRefreshControl)
loadData()
self.tableView.reloadData()
refreshControl.endRefreshing()

......










share|improve this question
































    0















    I have a UIViewController, inside which there is a tableView. I added a RefreshControl. But when I pull, it always jumps for some times, which is not smooth and continuous at all.



    I'm using Swift 4 and Xcode 10.1.



    class ItemsController: UIViewController, UITableViewDelegate, UITableViewDataSource, UITextViewDelegate, ItemCellDelegate 
    ......
    lazy var refreshControl: UIRefreshControl =
    let refreshControl = UIRefreshControl()
    refreshControl.addTarget(self, action:
    #selector(handleRefresh(_:)),
    for: UIControl.Event.valueChanged)
    refreshControl.tintColor = UIColor.lightGray

    return refreshControl
    ()
    ......
    override func viewDidLoad()
    // Refresh
    self.tableView.refreshControl = self.refreshControl

    ......
    @objc func handleRefresh(_ refreshControl: UIRefreshControl)
    loadData()
    self.tableView.reloadData()
    refreshControl.endRefreshing()

    ......










    share|improve this question




























      0












      0








      0


      0






      I have a UIViewController, inside which there is a tableView. I added a RefreshControl. But when I pull, it always jumps for some times, which is not smooth and continuous at all.



      I'm using Swift 4 and Xcode 10.1.



      class ItemsController: UIViewController, UITableViewDelegate, UITableViewDataSource, UITextViewDelegate, ItemCellDelegate 
      ......
      lazy var refreshControl: UIRefreshControl =
      let refreshControl = UIRefreshControl()
      refreshControl.addTarget(self, action:
      #selector(handleRefresh(_:)),
      for: UIControl.Event.valueChanged)
      refreshControl.tintColor = UIColor.lightGray

      return refreshControl
      ()
      ......
      override func viewDidLoad()
      // Refresh
      self.tableView.refreshControl = self.refreshControl

      ......
      @objc func handleRefresh(_ refreshControl: UIRefreshControl)
      loadData()
      self.tableView.reloadData()
      refreshControl.endRefreshing()

      ......










      share|improve this question
















      I have a UIViewController, inside which there is a tableView. I added a RefreshControl. But when I pull, it always jumps for some times, which is not smooth and continuous at all.



      I'm using Swift 4 and Xcode 10.1.



      class ItemsController: UIViewController, UITableViewDelegate, UITableViewDataSource, UITextViewDelegate, ItemCellDelegate 
      ......
      lazy var refreshControl: UIRefreshControl =
      let refreshControl = UIRefreshControl()
      refreshControl.addTarget(self, action:
      #selector(handleRefresh(_:)),
      for: UIControl.Event.valueChanged)
      refreshControl.tintColor = UIColor.lightGray

      return refreshControl
      ()
      ......
      override func viewDidLoad()
      // Refresh
      self.tableView.refreshControl = self.refreshControl

      ......
      @objc func handleRefresh(_ refreshControl: UIRefreshControl)
      loadData()
      self.tableView.reloadData()
      refreshControl.endRefreshing()

      ......







      ios swift uitableview uirefreshcontrol






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 28 at 16:59









      Bhaumik

      9131 gold badge6 silver badges17 bronze badges




      9131 gold badge6 silver badges17 bronze badges










      asked Mar 28 at 16:39









      Victor LiVictor Li

      306 bronze badges




      306 bronze badges

























          4 Answers
          4






          active

          oldest

          votes


















          1
















          I also faced that kind of problem. You can use this approach below:




          1. Change your handleRefresh method like this:



            @objc func handleRefresh(_ refreshControl: UIRefreshControl) 
            if !tableView.isDragging
            refresh() // refresh is another method for your reloading jobs






          2. Add refresh method.



            func refresh() 
            self.refreshControl.endRefreshing()
            self.tableView.reloadData()




          3. Lastly you need to implement scrollViewDidEndDragging. If you've pulled down far enough, the refreshControl will be refreshing, so call refresh. Otherwise, you either haven't pulled down far enough, you were dragging on a different part of the table, or you dragged so quickly that the refreshControl ValueChanged event has yet to fire, and it will refresh the table there.



            func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) 
            if refreshControl.isRefreshing == true
            refresh()








          share|improve this answer
































            0
















            Is loadData() asynchronous? because if so it should have a completion handler and



            tableView.reloadData()
            refreshControl.endRefreshing()


            should be done (on the main thread) from there. Otherwise what is happening is the user pulls down and you instantly update the tableView and stop the refresh control, so thats why you have no animation.






            share|improve this answer

























            • So how do I do these after loadData() is completed?

              – Victor Li
              Mar 28 at 18:26


















            0
















            try



            @objc func handleRefresh(_ refreshControl: UIRefreshControl) {
            loadData()
            self.tableView.reloadData()
            DispatchQueue.main.async
            //DispatchQueue.main.asyncAfter(deadline: .now + 0.2) // or this one with
            //short delay
            refreshControl.endRefreshing()







            share|improve this answer

























            • Thank you! This makes the animation become smoother, but there is still a little bit of jumping.

              – Victor Li
              Mar 28 at 18:43


















            0
















            I just solved this problem by doing this:



            @objc func handleRefresh(_ refreshControl: UIRefreshControl) 

            refreshControl.endRefreshing()


            func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool)

            loadData()



            Pretty simple. Now the animation is much better.
            The tableView.reloadData(), which is inside of loadData(), is getting the animation less smooth. So I make it do after the user releases from dragging.






            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/4.0/"u003ecc by-sa 4.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%2f55402810%2fswift-4-refresh-control-not-smooth-but-always-jump%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1
















              I also faced that kind of problem. You can use this approach below:




              1. Change your handleRefresh method like this:



                @objc func handleRefresh(_ refreshControl: UIRefreshControl) 
                if !tableView.isDragging
                refresh() // refresh is another method for your reloading jobs






              2. Add refresh method.



                func refresh() 
                self.refreshControl.endRefreshing()
                self.tableView.reloadData()




              3. Lastly you need to implement scrollViewDidEndDragging. If you've pulled down far enough, the refreshControl will be refreshing, so call refresh. Otherwise, you either haven't pulled down far enough, you were dragging on a different part of the table, or you dragged so quickly that the refreshControl ValueChanged event has yet to fire, and it will refresh the table there.



                func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) 
                if refreshControl.isRefreshing == true
                refresh()








              share|improve this answer





























                1
















                I also faced that kind of problem. You can use this approach below:




                1. Change your handleRefresh method like this:



                  @objc func handleRefresh(_ refreshControl: UIRefreshControl) 
                  if !tableView.isDragging
                  refresh() // refresh is another method for your reloading jobs






                2. Add refresh method.



                  func refresh() 
                  self.refreshControl.endRefreshing()
                  self.tableView.reloadData()




                3. Lastly you need to implement scrollViewDidEndDragging. If you've pulled down far enough, the refreshControl will be refreshing, so call refresh. Otherwise, you either haven't pulled down far enough, you were dragging on a different part of the table, or you dragged so quickly that the refreshControl ValueChanged event has yet to fire, and it will refresh the table there.



                  func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) 
                  if refreshControl.isRefreshing == true
                  refresh()








                share|improve this answer



























                  1














                  1










                  1









                  I also faced that kind of problem. You can use this approach below:




                  1. Change your handleRefresh method like this:



                    @objc func handleRefresh(_ refreshControl: UIRefreshControl) 
                    if !tableView.isDragging
                    refresh() // refresh is another method for your reloading jobs






                  2. Add refresh method.



                    func refresh() 
                    self.refreshControl.endRefreshing()
                    self.tableView.reloadData()




                  3. Lastly you need to implement scrollViewDidEndDragging. If you've pulled down far enough, the refreshControl will be refreshing, so call refresh. Otherwise, you either haven't pulled down far enough, you were dragging on a different part of the table, or you dragged so quickly that the refreshControl ValueChanged event has yet to fire, and it will refresh the table there.



                    func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) 
                    if refreshControl.isRefreshing == true
                    refresh()








                  share|improve this answer













                  I also faced that kind of problem. You can use this approach below:




                  1. Change your handleRefresh method like this:



                    @objc func handleRefresh(_ refreshControl: UIRefreshControl) 
                    if !tableView.isDragging
                    refresh() // refresh is another method for your reloading jobs






                  2. Add refresh method.



                    func refresh() 
                    self.refreshControl.endRefreshing()
                    self.tableView.reloadData()




                  3. Lastly you need to implement scrollViewDidEndDragging. If you've pulled down far enough, the refreshControl will be refreshing, so call refresh. Otherwise, you either haven't pulled down far enough, you were dragging on a different part of the table, or you dragged so quickly that the refreshControl ValueChanged event has yet to fire, and it will refresh the table there.



                    func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) 
                    if refreshControl.isRefreshing == true
                    refresh()









                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 28 at 18:52









                  Imrul KayesImrul Kayes

                  4961 gold badge6 silver badges15 bronze badges




                  4961 gold badge6 silver badges15 bronze badges


























                      0
















                      Is loadData() asynchronous? because if so it should have a completion handler and



                      tableView.reloadData()
                      refreshControl.endRefreshing()


                      should be done (on the main thread) from there. Otherwise what is happening is the user pulls down and you instantly update the tableView and stop the refresh control, so thats why you have no animation.






                      share|improve this answer

























                      • So how do I do these after loadData() is completed?

                        – Victor Li
                        Mar 28 at 18:26















                      0
















                      Is loadData() asynchronous? because if so it should have a completion handler and



                      tableView.reloadData()
                      refreshControl.endRefreshing()


                      should be done (on the main thread) from there. Otherwise what is happening is the user pulls down and you instantly update the tableView and stop the refresh control, so thats why you have no animation.






                      share|improve this answer

























                      • So how do I do these after loadData() is completed?

                        – Victor Li
                        Mar 28 at 18:26













                      0














                      0










                      0









                      Is loadData() asynchronous? because if so it should have a completion handler and



                      tableView.reloadData()
                      refreshControl.endRefreshing()


                      should be done (on the main thread) from there. Otherwise what is happening is the user pulls down and you instantly update the tableView and stop the refresh control, so thats why you have no animation.






                      share|improve this answer













                      Is loadData() asynchronous? because if so it should have a completion handler and



                      tableView.reloadData()
                      refreshControl.endRefreshing()


                      should be done (on the main thread) from there. Otherwise what is happening is the user pulls down and you instantly update the tableView and stop the refresh control, so thats why you have no animation.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Mar 28 at 17:03









                      Josh HomannJosh Homann

                      9,8442 gold badges16 silver badges24 bronze badges




                      9,8442 gold badges16 silver badges24 bronze badges















                      • So how do I do these after loadData() is completed?

                        – Victor Li
                        Mar 28 at 18:26

















                      • So how do I do these after loadData() is completed?

                        – Victor Li
                        Mar 28 at 18:26
















                      So how do I do these after loadData() is completed?

                      – Victor Li
                      Mar 28 at 18:26





                      So how do I do these after loadData() is completed?

                      – Victor Li
                      Mar 28 at 18:26











                      0
















                      try



                      @objc func handleRefresh(_ refreshControl: UIRefreshControl) {
                      loadData()
                      self.tableView.reloadData()
                      DispatchQueue.main.async
                      //DispatchQueue.main.asyncAfter(deadline: .now + 0.2) // or this one with
                      //short delay
                      refreshControl.endRefreshing()







                      share|improve this answer

























                      • Thank you! This makes the animation become smoother, but there is still a little bit of jumping.

                        – Victor Li
                        Mar 28 at 18:43















                      0
















                      try



                      @objc func handleRefresh(_ refreshControl: UIRefreshControl) {
                      loadData()
                      self.tableView.reloadData()
                      DispatchQueue.main.async
                      //DispatchQueue.main.asyncAfter(deadline: .now + 0.2) // or this one with
                      //short delay
                      refreshControl.endRefreshing()







                      share|improve this answer

























                      • Thank you! This makes the animation become smoother, but there is still a little bit of jumping.

                        – Victor Li
                        Mar 28 at 18:43













                      0














                      0










                      0









                      try



                      @objc func handleRefresh(_ refreshControl: UIRefreshControl) {
                      loadData()
                      self.tableView.reloadData()
                      DispatchQueue.main.async
                      //DispatchQueue.main.asyncAfter(deadline: .now + 0.2) // or this one with
                      //short delay
                      refreshControl.endRefreshing()







                      share|improve this answer













                      try



                      @objc func handleRefresh(_ refreshControl: UIRefreshControl) {
                      loadData()
                      self.tableView.reloadData()
                      DispatchQueue.main.async
                      //DispatchQueue.main.asyncAfter(deadline: .now + 0.2) // or this one with
                      //short delay
                      refreshControl.endRefreshing()








                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Mar 28 at 18:30









                      Hen ShabatHen Shabat

                      12410 bronze badges




                      12410 bronze badges















                      • Thank you! This makes the animation become smoother, but there is still a little bit of jumping.

                        – Victor Li
                        Mar 28 at 18:43

















                      • Thank you! This makes the animation become smoother, but there is still a little bit of jumping.

                        – Victor Li
                        Mar 28 at 18:43
















                      Thank you! This makes the animation become smoother, but there is still a little bit of jumping.

                      – Victor Li
                      Mar 28 at 18:43





                      Thank you! This makes the animation become smoother, but there is still a little bit of jumping.

                      – Victor Li
                      Mar 28 at 18:43











                      0
















                      I just solved this problem by doing this:



                      @objc func handleRefresh(_ refreshControl: UIRefreshControl) 

                      refreshControl.endRefreshing()


                      func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool)

                      loadData()



                      Pretty simple. Now the animation is much better.
                      The tableView.reloadData(), which is inside of loadData(), is getting the animation less smooth. So I make it do after the user releases from dragging.






                      share|improve this answer





























                        0
















                        I just solved this problem by doing this:



                        @objc func handleRefresh(_ refreshControl: UIRefreshControl) 

                        refreshControl.endRefreshing()


                        func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool)

                        loadData()



                        Pretty simple. Now the animation is much better.
                        The tableView.reloadData(), which is inside of loadData(), is getting the animation less smooth. So I make it do after the user releases from dragging.






                        share|improve this answer



























                          0














                          0










                          0









                          I just solved this problem by doing this:



                          @objc func handleRefresh(_ refreshControl: UIRefreshControl) 

                          refreshControl.endRefreshing()


                          func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool)

                          loadData()



                          Pretty simple. Now the animation is much better.
                          The tableView.reloadData(), which is inside of loadData(), is getting the animation less smooth. So I make it do after the user releases from dragging.






                          share|improve this answer













                          I just solved this problem by doing this:



                          @objc func handleRefresh(_ refreshControl: UIRefreshControl) 

                          refreshControl.endRefreshing()


                          func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool)

                          loadData()



                          Pretty simple. Now the animation is much better.
                          The tableView.reloadData(), which is inside of loadData(), is getting the animation less smooth. So I make it do after the user releases from dragging.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 28 at 19:20









                          Victor LiVictor Li

                          306 bronze badges




                          306 bronze badges































                              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.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55402810%2fswift-4-refresh-control-not-smooth-but-always-jump%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

                              Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                              Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                              Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript