public TableViewSource(RefreshingUITableViewController rtvc)
 {
     _list = rtvc._list;
     _checkForRefresh = false;
     _reloading = false;
     _refreshHeaderView = rtvc._refreshHeaderView;
     _table = rtvc.TableView;
 }
    public override void ViewDidLoad()
    {
        base.ViewDidLoad ();

        _list = new List<string> {
            "Tangerine",
            "Mango",
            "Grapefruit",
            "Orange",
            "Banana"
        };

        _refreshHeaderView = new RefreshTableHeaderView ();
        _refreshHeaderView.BackgroundColor = new UIColor (226f, 231f, 237f, 1f);

        TableView.Source = new TableViewSource (this);
        TableView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;

        TableView.AddSubview (_refreshHeaderView);
    }
Esempio n. 3
0
        // add this string to the extra arguments for mtouch
        // -gcc_flags "-framework QuartzCore -L${ProjectDir} -lAdMobSimulator3_0 -ObjC"
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            checkForRefresh = false;
            reloading = false;

            list = new List<string>()
            {
                "Tangerine",
                "Mango",
                "Grapefruit",
                "Orange",
                "Banana"
            };

            tableView = new UITableView()
            {
                Delegate = new TableViewDelegate(list),
                DataSource = new TableViewDataSource(list),
                AutoresizingMask =
                    UIViewAutoresizing.FlexibleHeight|
                    UIViewAutoresizing.FlexibleWidth,
                //BackgroundColor = UIColor.Yellow,
            };

            // Set the table view to fit the width of the app.
            tableView.SizeToFit();

            // Reposition and resize the receiver
            tableView.Frame = new RectangleF (
                0, 0, this.View.Frame.Width,
                this.View.Frame.Height);

            RefreshTableHeaderView refreshHeaderView = new RefreshTableHeaderView();
            refreshHeaderView.BackgroundColor = new UIColor (226.0f,231.0f,237.0f,1.0f);
            tableView.AddSubview (refreshHeaderView);
            // Add the table view as a subview
            this.View.AddSubview(tableView);

            tableView.DraggingStarted += delegate {
                checkForRefresh = true;
            };

            tableView.Scrolled += delegate(object sender, EventArgs e) {

                if (checkForRefresh) {
                    if (refreshHeaderView.isFlipped && (tableView.ContentOffset.Y > - 65.0f) && (tableView.ContentOffset.Y < 0.0f) && !reloading)
                    {
                        refreshHeaderView.flipImageAnimated (true);
                        refreshHeaderView.setStatus (TableViewPullRefresh.RefreshTableHeaderView.RefreshStatus.PullToReloadStatus);
                    }
                    else if ((!refreshHeaderView.isFlipped) && (this.tableView.ContentOffset.Y < -65.0f))
                    {
                        refreshHeaderView.flipImageAnimated (true);
                        refreshHeaderView.setStatus(TableViewPullRefresh.RefreshTableHeaderView.RefreshStatus.ReleaseToReloadStatus );
                    }
                }
            };

            tableView.DraggingEnded += delegate(object sender, EventArgs e) {

                if (this.tableView.ContentOffset.Y <= -65.0f){
                    reloading = true;
                    //Reload your data here
                    refreshHeaderView.toggleActivityView();
                    UIView.BeginAnimations("ReloadingData");
                    UIView.SetAnimationDuration(0.2);
                    this.tableView.ContentInset = new UIEdgeInsets (60.0f,0.0f,0.0f,0.0f);
                    UIView.CommitAnimations();
                }

                checkForRefresh = false;

            };
        }
        // add this string to the extra arguments for mtouch
        // -gcc_flags "-framework QuartzCore -L${ProjectDir} -lAdMobSimulator3_0 -ObjC"
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            checkForRefresh = false;
            reloading = false;

            list = new List<string>()
            {
                "Tangerine",
                "Mango",
                "Grapefruit",
                "Orange",
                "Banana"
            };

            tableView = new UITableView()
            {
                Delegate = new TableViewDelegate(list),
                DataSource = new TableViewDataSource(list),
                AutoresizingMask =
                    UIViewAutoresizing.FlexibleHeight|
                    UIViewAutoresizing.FlexibleWidth,
                //BackgroundColor = UIColor.Yellow,
            };

            // Set the table view to fit the width of the app.
            tableView.SizeToFit();

            // Reposition and resize the receiver
            tableView.Frame = new RectangleF (
                0, 0, this.View.Frame.Width,
                this.View.Frame.Height);

            RefreshTableHeaderView refreshHeaderView = new RefreshTableHeaderView();
            refreshHeaderView.BackgroundColor = new UIColor (226.0f,231.0f,237.0f,1.0f);
            tableView.AddSubview (refreshHeaderView);
            // Add the table view as a subview
            this.View.AddSubview(tableView);

            tableView.DraggingStarted += delegate {
                checkForRefresh = true;
            };

            tableView.Scrolled += delegate(object sender, EventArgs e) {

                if (checkForRefresh) {
                    if (refreshHeaderView.isFlipped && (tableView.ContentOffset.Y > - 65.0f) && (tableView.ContentOffset.Y < 0.0f) && !reloading)
                    {
                        refreshHeaderView.flipImageAnimated (true);
                        refreshHeaderView.setStatus (TableViewPullRefresh.RefreshTableHeaderView.RefreshStatus.PullToReloadStatus);
                    }
                    else if ((!refreshHeaderView.isFlipped) && (this.tableView.ContentOffset.Y < -65.0f))
                    {
                        refreshHeaderView.flipImageAnimated (true);
                        refreshHeaderView.setStatus(TableViewPullRefresh.RefreshTableHeaderView.RefreshStatus.ReleaseToReloadStatus );
                    }
                }
            };

            tableView.DraggingEnded += delegate(object sender, EventArgs e) {

                if (this.tableView.ContentOffset.Y <= -65.0f){

                    //ReloadTimer = NSTimer.CreateRepeatingScheduledTimer (new TimeSpan (0, 0, 0, 10, 0), () => dataSourceDidFinishLoadingNewData ());
                    ReloadTimer = NSTimer.CreateScheduledTimer (new TimeSpan (0, 0, 0, 5, 0),
                                                                delegate {
                                        // for this demo I cheated and am just going to pretend data is reloaded
                                        // in real world use this function to really make sure data is reloaded

                                        ReloadTimer = null;
                                        Console.WriteLine ("dataSourceDidFinishLoadingNewData() called from NSTimer");

                                        reloading = false;
                                        refreshHeaderView.flipImageAnimated (false);
                                        refreshHeaderView.toggleActivityView();
                                        UIView.BeginAnimations("DoneReloadingData");
                                        UIView.SetAnimationDuration(0.3);
                                        tableView.ContentInset = new UIEdgeInsets (0.0f,0.0f,0.0f,0.0f);
                                        refreshHeaderView.setStatus(TableViewPullRefresh.RefreshTableHeaderView.RefreshStatus.PullToReloadStatus);
                                        UIView.CommitAnimations();
                                        refreshHeaderView.setCurrentDate();
                    });

                    reloading = true;
                    tableView.ReloadData();
                    refreshHeaderView.toggleActivityView();
                    UIView.BeginAnimations("ReloadingData");
                    UIView.SetAnimationDuration(0.2);
                    this.tableView.ContentInset = new UIEdgeInsets (60.0f,0.0f,0.0f,0.0f);
                    UIView.CommitAnimations();
                }

                checkForRefresh = false;

            };
        }