Recherche…


Remarques

Références d'objet:

Table UITableView;
TableSource tableSource;
bool useRefreshControl = false;
UIRefreshControl RefreshControl;
List tableItems;

TableSource et TableItem sont des classes définies par l'utilisateur

Pour l'exemple complet, vous pouvez utiliser: https://github.com/adiiaditya/Xamarin.iOS-Samples/tree/master/PullToRefresh

Ajout de UIRefreshControl à UITableView

public override async void ViewDidLoad(){  
base.ViewDidLoad();  
// Perform any additional setup after loading the view, typically from a nib.  

Title = "Pull to Refresh Sample";  
table = new UITableView(new CGRect(0, 20, View.Bounds.Width, View.Bounds.Height - 20));  
//table.AutoresizingMask = UIViewAutoresizing.All;  
tableItems = new List<TableItem>();  
tableItems.Add(new TableItem("Vegetables") { ImageName = "Vegetables.jpg" });  
tableItems.Add(new TableItem("Fruits") { ImageName = "Fruits.jpg" });  
tableItems.Add(new TableItem("Flower Buds") { ImageName = "Flower Buds.jpg" });  
tableItems.Add(new TableItem("Legumes") { ImageName = "Legumes.jpg" });  
tableItems.Add(new TableItem("Tubers") { ImageName = "Tubers.jpg" });  
tableSource = new TableSource(tableItems);  
table.Source = tableSource;  

await RefreshAsync();  

AddRefreshControl();  

Add(table);  
table.Add(RefreshControl);
}

async Task RefreshAsync()  
{  
// only activate the refresh control if the feature is available  
if (useRefreshControl)  
    RefreshControl.BeginRefreshing();  

if (useRefreshControl)  
    RefreshControl.EndRefreshing();  

    table.ReloadData();  
}  

#region * iOS Specific Code  
// This method will add the UIRefreshControl to the table view if  
// it is available, ie, we are running on iOS 6+  
void AddRefreshControl()  
{  
if (UIDevice.CurrentDevice.CheckSystemVersion(6, 0))  
{  
    // the refresh control is available, let's add it  
    RefreshControl = new UIRefreshControl();  
    RefreshControl.ValueChanged += async (sender, e) =>  
    {  
        tableItems.Add(new TableItem("Bulbs") { ImageName = "Bulbs.jpg" });  
        await RefreshAsync();  
    };  
    useRefreshControl = true;  
   }    
}  
#endregion  


Modified text is an extract of the original Stack Overflow Documentation
Sous licence CC BY-SA 3.0
Non affilié à Stack Overflow