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

标签 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

*描述:*但是下面的部分代码给出了异常

* 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/

相关文章:

ios - 如何将大字符串传递给 iMessage 扩展?

ios - 比较重用标识符崩溃

iphone - 获取 UITableView Swift 中每一行的 RowHeight

ios - 在 uitableview 中获取特定行的实例

iphone - 如何在 iOS 上的 AVPlayer 或 MPMoviePlayerController 中选择音频 channel ?

iphone - UIToolbar initWithFrame 自动调整大小?

ios - 在 Swift 中调用 API 时出现问题

iphone - 如何显示被虚拟键盘隐藏的文本字段?

iphone - 二维坐标系中的等距投影

iphone - 同时缩放多个 View