我在 UITablViewSource 中使用以下代码
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
UIImage scaledImage=null;
string cellIdentifier = "NewsFeedCell";
var newsFeedCellItem = NewsFeedCellItemList [indexPath.Row];
var newsFeedCell = new NewsFeedCell (NewsFeedScreenInstance, newsFeedCellItem, cellIdentifier, indexPath);
if (newsFeedCell != null) {
if (!String.IsNullOrWhiteSpace (newsFeedCellItem.FeedItem.Picture.PreviewUrl)) {
var image = ImageStore.Get (newsFeedCellItem.FeedItem.Picture.PreviewUrl);
if(image != null)
{
newsFeedCellItem.FeedItem.Picture.Image = image;
scaledImage = ImageHelper.Scale(image, new SizeF (528, 528));
}
if (scaledImage != null) {
newsFeedCell.ScrapImage = scaledImage;
} else {
BeginDownloadImage (tableView, indexPath);
}
}
}
return newsFeedCell;
}
#endregion
#region PRIVATE METHODS
private void BeginDownloadImage (UITableView tableView, NSIndexPath indexPath)
{
Action successAction = () => {
this.BeginInvokeOnMainThread (() => {
tableView.BeginUpdates ();
tableView.ReloadRows (new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade);
tableView.EndUpdates ();
});
};
ImageStore.BeginDownloadImage(NewsFeedCellItemList [indexPath.Row].FeedItem.Picture.PreviewUrl, successAction);
}
#endregion
*描述: *但是下面的部分代码给出了异常
* -[Scrapboom.iPhone.NewsFeedTableView _endCellAnimationsWithContext:] 中的断言失败,/SourceCache/UIKit/UIKit-2903.2/UITableView.m:1076 并且应用程序被挂起或有时崩溃。
tableView.ReloadRows (new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade);