Chart is crashing when removed from View (MonoTouch)


#1

Actualy the problem startede when I wantede the make the user change the chart  - creating at new Chart Controlle was chrasing our app. I have made a small sample - showing the problem.  First push on the button create the chart - next push remove the chart - but the App is crashing! 

This dynamic removing controls is working perfect with ex. a UITableView or like in the Sample a UIButton.

using System;
using System.Drawing;

using MonoTouch.Foundation;
using MonoTouch.UIKit;

using ShinobiCharts; 

namespace ShinobiTest
{
    public partial class ShinobiTestViewController : UIViewController
    {
        private UIButton m_cButton;
        private UIView m_cView;
        private ChartTest m_cChart = null;
        private ChartTestDataSource m_cChartTestDataSource = null;

//          private   UIButton   m_cButtonTest  =  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_cButtonTest  ==  null )_
//__                {
//                      m_cButtonTest  =   UIButton . FromType_(UIButtonType . InfoLight );_
//                      m_cView . AddSubview_ ( m_cButtonTest );_
//__                }
//                  else_ {_
//                      m_cButtonTest . RemoveFromSuperview_();_
//                      m_cButtonTest  =  null_;_
//__                }

                if (m_cChart == null) {
                    m_cChart = new ChartTest( new RectangleF( 0, 0,  m_cView.Frame.Width, m_cView.Frame.Height ) );
                    m_cChartTestDataSource = new ChartTestDataSource();
                    m_cChart.DataSource = m_cChartTestDataSource;
                    m_cView.AddSubview ( m_cChart );
                }
                else {
                    m_cChart.RemoveFromSuperview();
                    m_cChart = null;
                    m_cChartTestDataSource = 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 ChartTest : ShinobiChart 
    {
        public ChartTest(RectangleF frame) : base(frame)
        {
        }
    }
    
    public class ChartTestDataSource : SChartDataSource 
    {
        
        public ChartTestDataSource()
        {
        }
        
        public override int GetNumberOfSeries (ShinobiCharts.ShinobiChart chart)
        {
            return 1;
        }
        
        public override int GetNumberOfDataPoints (ShinobiCharts.ShinobiChart chart, int dataSeriesIndex)
        {
            return 10;
        }
        
        public override SChartSeries GetSeries (ShinobiChart chart, int index)
        {
            SChartPieSeries pieSeries = new SChartPieSeries ();
            
            return pieSeries;
        }
        
        public override SChartData GetDataPoint (ShinobiChart chart, int dataIndex, int seriesIndex)
        {
            return new SChartRadialDataPoint ()
            {
                Name = dataIndex.ToString (),
                Value = new NSNumber ( 5 + dataIndex  )
            };
        }
    }
}


#2

Hi,

This seems to be the same issue as your other post “Grid crashes app (still) - (Monotouch)” and as you kindly emailed, the same workaround applies.

Robin