Grid bug - GetCell TextColor is not working (MonoTouch)


#1

The RowStyle TextColor overrules the cell.TextField.TextColor set in GetCell(). It is working by first view, but when scrolling all cell get the textcolor from the RowStyle - Setting .RowStylesTakePriority = False does not change this.

This bug is very simple to show. Set af Fixed Color in GetCell TextField.TextColor and Scroll. 


#2

Hi TheCalvin,

It’s hard be sure without seeing your code, but this sounds like the kind of problem I would associate with incorrect cell reuse. I tried it with the LargeDataSet sample app, adding

            spreadSheet.DefaultRowStyle.TextColor = UIColor.Red;

and everything worked fine, scrolling a cell in and out of view.

Grids uses a cell reuse mechanism, whereby only visible cells are held in memory, on screen or in one or more pools of cells from which the grid can reuse them. Each pool has a reuseIdentifier, so in general you would expect to have a pool for cells styled one way,  and another for differently styled ones, depending on the purpose of your styling (or any other distinguishing features).

The error you describe sounds like what I would expect if you had set the text colour of a cell but given it a reuse identifier shared with other cells with a different text colour. Everything’s fine while the cell is initially on screen, but when you scroll, it drops back into the pool. Next time it is scrolled into view the grid picks a cell out of the reuse pool, but there is no guarantee that it’s the same one you coloured (in fact it’s rather unlikely to be that one).

So *if this is the problem in your app* the solution is to use more than one reuse identifier, as the LargeDataSample does with “headerCell” and “bodyCell”.

Regards,

Robin Sillem 


#3

It is very simple to show - with this DataSource I expect all Cell to have at Yellow TextColor - just like I got at different text for each cell (even with reuse)  - but when scrolled all cell gets the TextColor for the RowStyle.

    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)
        {
            SGridAutoCell cell = grid.DequeueReusableCell (kReuseIdentifier) as SGridAutoCell;        
            if (cell == null)
                cell = new SGridAutoCell (kReuseIdentifier);
            
            cell.TextField.Text = gridCoord.RowIndex.ToString () + ‘,’ + gridCoord.Column.ToString ();
            cell.TextField.TextColor = UIColor.Yellow;

            return cell;
        }
        
        [Export (“conformsToProtocol:”)]
        public override bool ConformsToProtocol (IntPtr protocol)
        {
            return base.ConformsToProtocol(protocol);
        }
    }


#4

Hi TheCalvin,

The line

                    _cellCache.Add(cell);

you have removed from the sample app is indeed required for memory management purposes in the MonoTouch version of ShinobiGrids.  Note that the memory management model in MonoTouch is very different from that in native objective C and hence why you can’t find similar issues in Apple’s documentation. I am, however, sure this is not a bug in the ShinobiGrids implementation but rather an subtlety in the way MonoTouch has to handle memory management and KVO code in the native implementation, and it is a specific point of difference between ShinobiGrids and UITableView with MonoTouch.

If you require additional implementation support or to continue this discussion, please raise a support ticket via our customer portal (available to customers who have purchased the ShinobiCare Plus package). 

Regards,

Robin Sillem