Grid slow (bug?) - using FreezeRows and Reload


#1

This include small sample shows the problem. Scroll down To Ex. Row 200 and click a cell (this sample forces a reload) - now all cells form Row 0 to Row 200 are read twice, when using heavy calculations in each cell this result in a very slow performance. Without FreezeRows the Reload only reads the the visible cells (like expected) ones! Any solution?

using System;

using System.Drawing;

using MonoTouch.Foundation;
using MonoTouch.UIKit;

using ShinobiCharts; 
using ShinobiGrids ;

namespace ShinobiTest
{
    public partial class ShinobiTestViewController : UIViewController
    {
        private UIButton m_cButton;
        private UIView m_cView;

        private SampleGrid m_cGrid = null;
        private SimpleGridDelegate m_cGridDelegate = null;
        private SimpleGridDataSource m_cGridDataSource = null;

        public ShinobiTestViewController () : base (“ShinobiTestViewController”, null)
        {
        }
        
        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();

            m_cButton = UIButton.FromType(UIButtonType.InfoDark );
            m_cButton.TouchDown += (sender, e) => 
            {
                if (m_cGrid == null) {
                    m_cGrid = new SampleGrid(new RectangleF( 0, 0,  m_cView.Frame.Width, m_cView.Frame.Height ));
                    m_cGrid.ConfigureStyles ();
                    m_cGridDataSource = new SimpleGridDataSource();
                    m_cGridDelegate = new SimpleGridDelegate();

                    m_cGrid.DataSource = m_cGridDataSource;
                    m_cGrid.Delegate = m_cGridDelegate;
                    m_cView.AddSubview ( m_cGrid );
                }
                else {
                    m_cGrid.RemoveFromSuperview();
                    try {
                        m_cGrid.Dispose ();

                    } catch (ArgumentNullException ) {}

                    m_cGrid = null;
                    m_cGridDataSource = null;
                    m_cGridDelegate = null;
                }
};
            this.View.AddSubview (m_cButton);

            m_cView = new UIView( new RectangleF( 50, 50, 400, 400 ));
            m_cView.BackgroundColor = UIColor.Red;

            this.View.AddSubview (m_cView);
        }
    }

    public class SampleGrid : ShinobiGrid
    {
        public SampleGrid ( RectangleF frame ) : base (frame)
        {
        }

        public SampleGrid ( IntPtr handle ) : base (handle)
        {
        }

        public void ConfigureStyles()
        {
            FreezeRowsAboveAndIncluding ( new SGridRow(  0, 0 ) );
        }
    }
    
    public class SimpleGridDelegate : SGridDelegate 
    {
        public SimpleGridDelegate ()
        {
        }

        protected override void OnSelectedCell (ShinobiGrid grid, SGridCoord gridCoord)
        {
            grid.Reload ();
        }
    }
    
    public class SimpleGridDataSource : SGridDataSource
    {
        private const string kReuseIdentifier = “MyCell”;
        
        public SimpleGridDataSource( )
        {
        }
        
        protected override uint GetNumberOfRows(ShinobiGrid grid, int sectionIndex)
        {
            return (uint) 1000;
        }
        
        protected override uint GetNumberOfCols(ShinobiGrid grid)
        {
            return (uint) 10;
        }
        
        protected override SGridCell GetCell (ShinobiGrid grid, SGridCoord gridCoord)
        {
           Console.WriteLine ( gridCoord.RowIndex.ToString () + ‘,’ + gridCoord.Column.ToString () );

            SGridAutoCell cell = grid.DequeueReusableCell (kReuseIdentifier) as SGridAutoCell;        
            if (cell == null)
                cell = new SGridAutoCell (kReuseIdentifier);
            
            cell.TextField.Text = gridCoord.RowIndex.ToString () + ‘,’ + gridCoord.Column.ToString ();
            
            return cell;
        }
        
        [Export (“conformsToProtocol:”)]
        public override bool ConformsToProtocol (IntPtr protocol)
        {
            return base.ConformsToProtocol(protocol);
        }
    }
}


#2

Any news about this problem - the Issue is really slowing our solution?


#3

Hi TheCalvin,

We’re sorry that you’re having this problem with ShinobiGrids. We believe this to be an issue in our code that is causing the data source to be queried twice. We hope to have a fix for this problem ready for our next release in March.

A possible workaround would be to cache the result of this expensive work for your cells so that repeated calls to the data source do not require the work to be done again.