public void UpdateCell(SampleRowModel model) { int tagForRequest = Tag; ImageView.Image = UIImage.FromBundle("loading_1"); ImageView.Layer.AddAnimation(AnimationHelpers.GetSpinAnimation(), RotationAnimationKey); TextLabel.Text = model.Description; GetImageAsync(model.ImageUrl).ContinueWith(task => { InvokeOnMainThread(() => { // Scrolling up and down will spin up multiple requests for the same recycled cell object. // Make sure we only load the one appropriate for the currently displayed data. // NOTE: This would be a good place to implement a limited-concurrency request queue. // NOTE: This would be a good place to implement request cancellation, too. int currentTag = Tag; if (currentTag == tagForRequest) { // Remove the spinning animation (hilarious if you don't). ImageView.Layer.RemoveAnimation(RotationAnimationKey); UIImage result = task.Result; if (result != null) { // Only showing an image if one came back successfully. ImageView.Image = result; } } }); }); }
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { SampleRowModel model = rows[indexPath.Row]; SampleTableCell cell = (SampleTableCell)tableView.DequeueReusableCell(cellKey); if (cell == null) { cell = new SampleTableCell(cellKey); } cell.Tag = indexPath.Row; cell.UpdateCell(model); return(cell); }