我在 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
*描述:*但是下面的部分代码给出了异常
* Assertion failure in -[Scrapboom.iPhone.NewsFeedTableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-2903.2/UITableView.m:1076 and application is get hanged or sometimes crashing.
tableView.ReloadRows (new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade);
最佳答案
你的 GetCell
实现看起来不对。你应该尝试Dequeue
一个单元格,如果失败则创建一个单元格(在 iOS6+ 中甚至不需要 Register*ForCellReuse
:
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
string cellIdentifier = "NewsFeedCell";
var newsFeedCell = tableView.DequeueReusableCell (cellIdentifier) as NewsFeedCell;
//only required if you haven't used Register*ForCellReuse
if (newsFeedCell == null)
newsFeedCell = new NewsFeedCell (..., cellIdentifier,...);
//update your cell image and components here.
}
要了解更多信息,请阅读 tutorials .
如果环顾四周,您还会发现行之有效的工作模式,可以在表格单元格中延迟加载图像。并不是说您的第一眼看起来不对,而是这种情况并不常见。
关于iphone - ***断言失败-[Scrapboom.iPhone.NewsFeedTableView _endCellAnimationsWithContext :],/SourceCache/UIKit/UIKit-2903.2/UITableView.m:1076,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19418971/