带有触摸动画的 TableView 扩展和折叠部分 [英] TableView expanding and collapsing section with animation on touch

查看:18
本文介绍了带有触摸动画的 TableView 扩展和折叠部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已填充数据的列表,触摸时我希望该部分展开并删除前一个展开部分中的行.同样在第 0 部分,我有一个不使用触摸识别的促销视图,这是导致_restaurantModelDetails.Menu.Regular[(int)section - _isPromoView].Products.CountisPromoView 的值为 1我尝试了不同的方法,我在这里公开的方法在第二次点击时 EndUpdates() 有以下问题,第一个没有任何反应;

I have a list already populated with data, on touch i want the section to expand and delete the rows from the previous expanded section. Also in section 0 i have a Promotion View that doesn t use touch recognition, this is the cause for the _restaurantModelDetails.Menu.Regular[(int)section - _isPromoView].Products.Count isPromoView has a value of 1 I tried different methods, the one i expose here has the following problems on EndUpdates() at the second click, on the first one nothing happens;

NSInternalInconsistencyException 原因:无效更新:第 6 节中的行数无效.更新后现有节中包含的行数 (6) 必须等于更新前该节中包含的行数 (0), 加上或减去从该部分插入或删除的行数(0 插入,0 删除),加上或减去移入或移出该部分的行数(0 移入,0 移出).

NSInternalInconsistencyException Reason: Invalid update: invalid number of rows in section 6. The number of rows contained in an existing section after the update (6) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).

这是触摸处理程序

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;
}

推荐答案

我发现了我遇到的问题.

I found the problem that i was having.

我从

tableView.NumberOfRowsInSection(section)

0

修复是从

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

这篇关于带有触摸动画的 TableView 扩展和折叠部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆