***断言失败 - [Scrapboom.iPhone.NewsFeedTableView _endCellAnimationsWithContext:],/ SourceCache / UIKit / UIKit-2903.2 /UITableView.m:1076

时间:2013-10-17 05:34:19

标签: iphone ios uitableview xamarin.ios

我在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);

1 个答案:

答案 0 :(得分:2)

您的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

如果环顾四周,您还会发现经验证的工作模式可以懒散地在表格单元格中加载图像。并不是说你的第一眼就看错了,但这种情况并不常见。