簡體   English   中英

TableView展開和折疊部分帶有觸摸動畫

[英]TableView expanding and collapsing section with animation on touch

我有一個已經填充了數據的列表,在觸摸時我希望該部分展開並從上一個展開的部分中刪除行。 同樣在第0部分中,我有一個不使用觸摸識別的升級視圖,這是_restaurantModelDetails.Menu.Regular[(int)section - _isPromoView].Products.Count isPromoView的值,我嘗試了不同的方法,我在此處公開的內容在第二次單擊時在EndUpdates()上存在以下問題,在第一次單擊時沒有任何反應;

NSInternalInconsistencyException原因:無效的更新:第6節中的行數無效。更新(6)之后,現有節中包含的行數必須等於更新(0)之前該節中包含的行數,再加上或減去從該部分插入或刪除的行數(插入0,刪除0),再加上或減去移入或移出該部分的行數(移入0,移出0)。

這是觸摸處理器

void SectionHeaderViewOpened( UITableView tableView, int section)
{
    List indexPathsToInsert = new List( );
    List indexPathsToDelete = new List();

    for (int i = 0; i < tableView.NumberOfRowsInSection(section); i++)
    {
        indexPathsToInsert.Add(NSIndexPath.FromRowSection(i, section));
    }

    if(_sectionOpen != -1)
        for (int i = 0; i < tableView.NumberOfRowsInSection(_sectionOpen); i++)
        {
            indexPathsToDelete.Add(NSIndexPath.FromRowSection(i, _sectionOpen));
        }

    UITableViewRowAnimation insertAnimation;
    UITableViewRowAnimation deleteAnimation;

    if ( _sectionOpen == -1 || section < _sectionOpen )
    {
        insertAnimation = UITableViewRowAnimation.Top;
        deleteAnimation = UITableViewRowAnimation.Bottom;
    }
    else
    {
        insertAnimation = UITableViewRowAnimation.Bottom;
        deleteAnimation = UITableViewRowAnimation.Top;
    }

    //tableView.reloadData();

    tableView.BeginUpdates();
    tableView.DeleteRows(indexPathsToDelete.ToArray(), deleteAnimation);
    tableView.InsertRows(indexPathsToInsert.ToArray(), insertAnimation);
    tableView.EndUpdates(  );

    _sectionOpen = section;
}

public override UITableViewCell GetCell( UITableView tableView, NSIndexPath indexPath )
{
    RestaurantRow cell;

    var product = _restaurantModelDetails.Menu.Regular[indexPath.Section - _isPromoView].Products[indexPath.Row];
    cell = (RestaurantRow)tableView.DequeueReusableCell(CellIdentifier) ?? new RestaurantRow(product.Name);

    return cell;
}

public override nint RowsInSection( UITableView tableView, nint section )
{
    //Resturn number of products
    if ( section == _sectionOpen )
    {
        return _restaurantModelDetails.Menu.Regular[(int)section - _isPromoView].Products.Count;
    }

    return 0;
}

我發現了我遇到的問題。

我正在從中獲取行數

tableView.NumberOfRowsInSection(section)

這是0

解決方法是從中獲取行

_restaurantModelDetails.Menu.Regular[section - _isPromoView].Products.Count

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM