Beispiel #1
0
        // The ViewDidLoad() method is called when the view is first requested by the application.
        // The "async" keyword is added here to the override in order to allow other awaited async method calls inside the override to be called ascynchronously.
        public override async void ViewDidLoad()
        {
            base.ViewDidLoad();

            // tell the table view source to load the data
            await _AcquaintanceTableViewSource.LoadAcquaintances();

            SetTableViewProperties();

            // override the back button text for AcquaintanceDetailViewController (the navigated-to view controller)
            NavigationItem.BackBarButtonItem = new UIBarButtonItem("List", UIBarButtonItemStyle.Plain, null);
        }
        // The ViewDidLoad() method is called when the view is first requested by the application.
        // The "async" keyword is added here to the override in order to allow other awaited async method calls inside the override to be called ascynchronously.
        public override async void ViewDidLoad()
        {
            base.ViewDidLoad();

            // tell the table view source to load the data
            await _AcquaintanceTableViewSource.LoadAcquaintances();

            SetTableViewProperties();
        }
Beispiel #3
0
        async Task RefreshAcquaintances()
        {
            // ! flag to indicate how this refresh command was instantiated.
            bool triggeredByPullToRefresh = false;

            // Store the original offset of the TableView.
            var originalOffset = new CGPoint(TableView.ContentOffset.X, TableView.ContentOffset.Y);

            // If
            if (RefreshControl.Refreshing)
            {
                triggeredByPullToRefresh = true;
            }

            try
            {
                // If this refresh has not been started by a pull-to-refresh UI action, then we need to manually set the tableview offset to SHOW the refresh indicator.
                if (!triggeredByPullToRefresh)
                {
                    TableView.SetContentOffset(new CGPoint(originalOffset.X, originalOffset.Y - RefreshControl.Frame.Size.Height), true);
                }

                // Starts animating the refreshing indicator, and sets its Refreshing property to true.
                RefreshControl.BeginRefreshing();

                // request the TableViewSource to load acquaintances
                await _AcquaintanceTableViewSource.LoadAcquaintances();

                // Tell the TableView to update its UI (reload the cells) because the TableViewSource has updated.
                TableView.ReloadData();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"Error getting acquaintances: {ex.Message}");

                // present an alert about the failure
                using (var alert = new UIAlertView("Error getting acquaintances", "Ensure you have a network connection, and that a valid backend service URL is present in the app settings.", null, "OK"))
                {
                    alert.Show();
                }
            }
            finally
            {
                // Starts animating the refreshing indicator, and sets its Refreshing property to false.
                RefreshControl.EndRefreshing();

                // If this refresh has not been started by a pull-to-refresh UI action, then we need to manually set the tableview offset to HIDE the refresh indicator.
                if (!triggeredByPullToRefresh)
                {
                    TableView.SetContentOffset(originalOffset, true);
                }
            }
        }