Sök…


Anmärkningar

Objektreferenser:

UITableView-tabell;
TableSource tableSource;
bool useRefreshControl = falsk;
UIRefreshControl RefreshControl;
Lista tabellItem;

TableSource och TableItem är användardefinierade klasser

För hela provet kan du gaffla: https://github.com/adiiaditya/Xamarin.iOS-Samples/tree/master/PullToRefresh

Lägga till UIRefreshControl i 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
Licensierat under CC BY-SA 3.0
Inte anslutet till Stack Overflow