[英]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.