TableView扩展和折叠部分,触摸动画

时间:2015-04-23 12:18:42

标签: c# ios uitableview xamarin

我有一个已经填充了数据的列表,在触摸时我希望该部分展开并删除上一个展开部分中的行。同样在第0部分,我有一个不使用触摸识别的促销视图,这是原因 _restaurantModelDetails.Menu.Regular[(int)section - _isPromoView].Products.Count isPromoView的值为1 我尝试了不同的方法,我在这里公开的方法在第二次点击时在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;
}

1 个答案:

答案 0 :(得分:0)

我发现了我遇到的问题。

我从

获取了我的行数
tableView.NumberOfRowsInSection(section)

来自0

修复是从

获取行
_restaurantModelDetails.Menu.Regular[section - _isPromoView].Products.Count
相关问题