Why UIRefreshControl jumping?

前端 未结 4 1979
花落未央
花落未央 2020-12-18 01:35

I try to use the UIRefreshControl with swift 1.2 and works fine except the UI. It is jumping and I dont know why. Here is what I am doing:

class ViewControll         


        
相关标签:
4条回答
  • 2020-12-18 01:40

    Try this One will working good

    var tableViewController = UITableViewController(style: UITableViewStyle.Plain)
    tableViewController.tableView = self.myTableView
    
    self.refreshControl = UIRefreshControl()
    self.refreshControl.addTarget(self, action: #selector(self.getConnections),forControlEvents: .ValueChanged)
    tableViewController.refreshControl = self.refreshControl
    
    0 讨论(0)
  • 2020-12-18 01:45

    I found a solution, it works:

    override func viewDidLoad() {
        super.viewDidLoad()
    
        self.refreshControl = UIRefreshControl()
        self.refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
        self.refreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
    
    
        var tableViewC = UITableViewController()
        tableViewC.refreshControl = self.refreshControl
    
        self.tableView = tableViewC.tableView
    
        self.view.addSubview(self.tableView)
    }
    
    0 讨论(0)
  • 2020-12-18 01:54

    For Xamarin.iOS it's looks like this:

    [Register ("MyViewController")]
    partial class MyViewController
    {
        [Outlet]
        public UITableView myTableView { get; set; }
    
        // ...
    }
    
    public partial class MyViewController : UIViewController
    {
        public UIRefreshControl myRefreshControl { get; set; }
    
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
    
            // ...
    
            this.myRefreshControl = new UIRefreshControl();
            this.myRefreshControl.AttributedTitle = new NSAttributedString("Load News from server...");
            this.myRefreshControl.AddTarget(this, new ObjCRuntime.Selector("RefreshSource"), UIControlEvent.ValueChanged);
    
            #region Fix the Jump problem
            UITableViewController tableViewController = new UITableViewController();
            tableViewController.TableView = this.myTableView;
            tableViewController.RefreshControl = this.myRefreshControl;
            #endregion
    
            #region Fix the unwanted first showing
            this.myRefreshControl.BeginRefreshing();
            this.myRefreshControl.EndRefreshing();
            #endregion
    
            // ...
        }
    
        [Export("RefreshSource")]
        private async void RefreshSource()
        {
            #region Edit source data
            await Task.Run(() =>
                {
                    Thread.Sleep(3000);
                });
            #endregion
    
            this.myTableView.ReloadData();
            this.myRefreshControl.EndRefreshing();
        }
    }
    
    0 讨论(0)
  • 2020-12-18 01:56

    I have experienced this problem and I believe it is because the UIRefreshControl was meant for UITableViewController.

    I think you should try to insert the view at index 0 like below. (Excuse the objective-c)

    [self.tableView insertSubview:_refreshControl atIndex:0];

    Edit

    Do you have code to stop the refreshControl?

        // End Refreshing
        if ([self.refreshControl isRefreshing]) {
            float delayInSeconds = 1.0;
    
            dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
            dispatch_after(popTime, dispatch_get_main_queue(), ^{
                [self.refreshControl endRefreshing];
    
            });
        }
    
    0 讨论(0)
提交回复
热议问题