Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS : Expandable list view not drawing newly added control
    primarykey
    data
    text
    <p>I am trying to create an expandable list view in iOS using Xamarin with MvvmCross.</p> <p>The scenario is that I have a listview, and when a row in the listview is selected, it expands (animates) to reveal a collection view, loaded in via lazyloading.</p> <p>Here is the code I have so far:</p> <p><strong>Adapter :</strong> </p> <pre><code>public class MercatoAnimatedExpandableTableSource : MvxTableViewSource { private readonly string _key; private readonly List&lt;object&gt; items; private Dictionary&lt;object, bool&gt; expandableState = new Dictionary&lt;object, bool&gt;(); public MercatoAnimatedExpandableTableSource(UITableView tableView, IEnumerable&lt;object&gt; items, UINib nib, string key) : base(tableView) { _key = key; this.items = items.ToList(); this.items.ForEach(x =&gt; expandableState[x] = true); tableView.RegisterNibForCellReuse(nib, key); } protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item) { var cell = tableView.DequeueReusableCell(_key); cell.Frame = new RectangleF(cell.Frame.X, cell.Frame.Y, cell.Frame.Width, GetHeightForRow(tableView, indexPath)); return cell; } public override void RowSelected(UITableView tableView, NSIndexPath indexPath) { base.RowSelected(tableView, indexPath); var isExpanded = expandableState[items[indexPath.Row]]; expandableState[items[indexPath.Row]] = !isExpanded; var row = this.GetCell(tableView, indexPath); (row as FamilysubgroupViewCell).ExpandCells(); tableView.ReloadRows(new[] { indexPath }, UITableViewRowAnimation.Automatic); } public override float GetHeightForRow(UITableView tableView, NSIndexPath indexPath) { var isExpanded = expandableState[items[indexPath.Row]]; if (isExpanded) { return 25; } return 400; } protected override object GetItemAt(NSIndexPath indexPath) { return items[indexPath.Row]; } } </code></pre> <p><strong>Cell :</strong> </p> <pre><code> public FamilySubgroupViewCell (IntPtr handle) : base (handle) { this.DelayBind(() =&gt; { this.FamilyCollectionViewContainer.BackgroundColor = UIColor.Blue; var bindingset = this.CreateBindingSet&lt;FamilySubgroupViewCell, FamilySubTypeViewModel&gt;(); bindingset.Bind(this.FamilyGroupTitleLabel).To(x =&gt; x.FamilySubType.FamilySubGroupDescription); bindingset.Bind(this.FamilyGroupDescLabel).To(x =&gt; x.FamilySubType.FamilySubGroupDetail); bindingset.Apply(); }); } public void ExpandCells(Action onUpdate) { var context = this.DataContext as FamilySubTypeViewModel; context.PopulateAndRun(() =&gt; { Debug.WriteLine("Populating Models complete : now showing cells"); var collection = new FamilySubGroupModelsCollection(); collection.ViewModel = context; Debug.WriteLine("FamilySubGroupCell : Showing {0} Items", context.FamilyModels.Count); this.FamilyCollectionViewContainer.Add(collection.View); if (onUpdate != null) onUpdate(); }); } </code></pre> <p><strong>Issue</strong></p> <p>So when a cell is selected, it flips the 'isExpanded' property which gives it a new height - that works fine. The cell is then sent a message to 'expand' the cell, which in turn loads a new collection and adds it to the view (via View outlet).</p> <p>However, the collection is never re-rendered on the view. It populates fine, adds to the view but it is never actually visible on the newly expanded cell. If i load it in when the cell is initially created in the DelayBind() method (ie - no lazy loading) then it works ok.</p> <p>Have tried things like redrawing the cell </p> <pre><code>this.Draw(this.Bounds); </code></pre> <p>after the collection was added to the view, but to no avail.</p> <p>What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload