Ejemplo n.º 1
0
        private void ExpandItem(int section)
        {
            // Return if current expanded item and item to expand are same.
            if (_singleExpandable && ItemExpandedState.Select((state, pos) => new Tuple <int, bool>(pos, state))
                .FirstOrDefault(arg => arg.Item2)?.Item1 == section)
            {
                return;
            }

            if (_singleExpandable)
            {
                for (var i = 0; i < ItemExpandedState.Count(); i++)
                {
                    if (ItemExpandedState[i])
                    {
                        CollapseItem(i);
                    }
                }
            }

            ItemExpandedState[section] = true;

            if (_listHeaderCells.TryGetValue(section, out var headerCell))
            {
                headerCell?.OnExpand();
            }

            var itemsInSection = (int)RowsInSection(TableView, section);

            if (itemsInSection <= 0)
            {
                return;
            }

            var rowsToAdd = new NSIndexPath[itemsInSection];

            for (var i = 0; i < itemsInSection; i++)
            {
                rowsToAdd[i] = NSIndexPath.FromRowSection(i, section);
            }

            TableView.InsertRows(rowsToAdd, UITableViewRowAnimation.None);
        }