Different approach to presenting views from a single controller

JeffRushJeffRush USMember ✭✭

I have an app with four views. For grins, I tried a different approach other than the typical storyboard. I have a single View Controller (called amazingly enough, ViewController.cs). I instantiate all four views in the ViewController's constructor because 99% of the time, they will all four be used. I show/hide them as needed based on events that get raised.

    public partial class ViewController : UIViewController
    {
        nfloat _Height = 0;
        nfloat _Width = 0;
        MainView _MainView;
        MySubView1 _MySubView1;
        MySubView2 _MySubView2;
        MySubView3 _MySubView3;

        public ViewController() : base("ViewController", null)
        {
            _Height = UIScreen.MainScreen.ApplicationFrame.Height;
            _Width = UIScreen.MainScreen.ApplicationFrame.Width;

            _MainView = new MainView(new CGRect(0, 20, _Width, _Height));
            _MySubView1 = new ..........
            _MySubView2 = new ..........
            _MySubView3 = new ..........

        }

I'm sure this is far from the ideal way of doing things. Just curious what would be considered the "cons" of such an approach. For example, I suppose there is more memory consumption up-front since I instantiate them at the beginning.

Sign In or Register to comment.