Getting my head round MVC - Login type app

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting my head round MVC - Login type app

AndyW
Just wondering if you could just help me get my head round MVC for my use case.

I'm writing an application that requires you to login in to my web service.

So I currently have two view controllers:
LoginView : UIViewController
MainApplicationView : UITabBarController

I've got some caching going on, so I don't always need to show the login screen on application start. So I either _window.AddSubItem the LoginView or the MainApplicationView.

If I set LoginView, on successful login this pushes the MainApplicationView Controller.

My question is, is this first bit correct? or should I use a UINavigationController in there somewhere?

My next question is, when you press the Logout button in MainApplicationView, what should this do? Push a new LoginView? or something else?

Thanks for you time.

T
Reply | Threaded
Open this post in threaded view
|

Re: Getting my head round MVC - Login type app

shellyshao
Hi, did you get this solved? I'm in the middle of doing something similar. Your help is greatly appreciated!
Reply | Threaded
Open this post in threaded view
|

Re: Getting my head round MVC - Login type app

AndyW
Hi

I'm not sure 100% sure I solved this nicely, I've ended up using two Windows, something like this:

        [Register ("AppDelegate")]
        public class AppDelegate : UIApplicationDelegate
        {
                UIWindow _loginWindow, _mainWindow;
               
                private UIViewController _loginViewController, _mainNavigationController;
       
                bool _signedIn;
                public override bool FinishedLaunching (UIApplication app, NSDictionary options)
                {
                        if (_signedIn) {
                                ShowMainWindow ();
                        } else
                                ShowLoginWindow ();
                        return true;
                }
               
                public void ShowLoginWindow ()
                {
                        if (_mainWindow != null) {
                                _mainWindow.Hidden = true;
                                _mainWindow.RemoveFromSuperview ();
                                _mainWindow.Dispose ();
                                _mainWindow = null;
                        }
                        _loginWindow = new UIWindow (UIScreen.MainScreen.Bounds);
                        _loginViewController = new LoginViewController ();
                        _loginWindow.RootViewController = _loginViewController;
                        _loginWindow.MakeKeyAndVisible ();
                }
               
                public void ShowMainWindow ()
                {
                        if (_loginWindow != null) {
                                _loginWindow.Hidden = true;
                                _loginWindow.RemoveFromSuperview ();
                                _loginWindow.Dispose ();
                                _loginWindow = null;
                        }
                        _mainWindow = new UIWindow (UIScreen.MainScreen.Bounds);
                        _mainNavigationController = new MainNavigationViewController ();
                        _mainWindow.RootViewController = _mainNavigationController;
                        _mainWindow.MakeKeyAndVisible ();
                }
        }


When My LoginWindow has done its jobs it just calls ShowMainWindow smth like this:

((AppDelegate)UIApplication.SharedApplication.Delegate).ShowMainWindow ();

Hope this helps.

Andy
Reply | Threaded
Open this post in threaded view
|

Re: Getting my head round MVC - Login type app

Jackson Harper

You also want to show your login window when the app goes inactive.  


On Thu, Feb 9, 2012 at 10:06 AM, trip <[hidden email]> wrote:
Hi

I'm not sure 100% sure I solved this nicely, I've ended up using two
Windows, something like this:

       [Register ("AppDelegate")]
       public class AppDelegate : UIApplicationDelegate
       {
               UIWindow _loginWindow, _mainWindow;

               private UIViewController _loginViewController, _mainNavigationController;

               bool _signedIn;
               public override bool FinishedLaunching (UIApplication app, NSDictionary
options)
               {
                       if (_signedIn) {
                               ShowMainWindow ();
                       } else
                               ShowLoginWindow ();
                       return true;
               }

               public void ShowLoginWindow ()
               {
                       if (_mainWindow != null) {
                               _mainWindow.Hidden = true;
                               _mainWindow.RemoveFromSuperview ();
                               _mainWindow.Dispose ();
                               _mainWindow = null;
                       }
                       _loginWindow = new UIWindow (UIScreen.MainScreen.Bounds);
                       _loginViewController = new LoginViewController ();
                       _loginWindow.RootViewController = _loginViewController;
                       _loginWindow.MakeKeyAndVisible ();
               }

               public void ShowMainWindow ()
               {
                       if (_loginWindow != null) {
                               _loginWindow.Hidden = true;
                               _loginWindow.RemoveFromSuperview ();
                               _loginWindow.Dispose ();
                               _loginWindow = null;
                       }
                       _mainWindow = new UIWindow (UIScreen.MainScreen.Bounds);
                       _mainNavigationController = new MainNavigationViewController ();
                       _mainWindow.RootViewController = _mainNavigationController;
                       _mainWindow.MakeKeyAndVisible ();
               }
       }


When My LoginWindow has done its jobs it just calls ShowMainWindow smth like
this:

((AppDelegate)UIApplication.SharedApplication.Delegate).ShowMainWindow ();

Hope this helps.

Andy

--
View this message in context: http://monotouch.2284126.n4.nabble.com/Getting-my-head-round-MVC-Login-type-app-tp3515200p4373150.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch


_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|

RE: Getting my head round MVC - Login type app

shellyshao
This post has NOT been accepted by the mailing list yet.
In reply to this post by AndyW
Hi Andy
Thanks for your reply. I'm wondering how to carry the user information to the new window after the login. In asp.net web development, we keep user information in a session after the login. But here I don't know if there is such concept like session?
Thanks,
Shelly 


Date: Thu, 9 Feb 2012 07:06:55 -0800
From: [hidden email]
To: [hidden email]
Subject: Re: Getting my head round MVC - Login type app

Hi

I'm not sure 100% sure I solved this nicely, I've ended up using two Windows, something like this:

        [Register ("AppDelegate")]
        public class AppDelegate : UIApplicationDelegate
        {
                UIWindow _loginWindow, _mainWindow;
               
                private UIViewController _loginViewController, _mainNavigationController;
       
                bool _signedIn;
                public override bool FinishedLaunching (UIApplication app, NSDictionary options)
                {
                        if (_signedIn) {
                                ShowMainWindow ();
                        } else
                                ShowLoginWindow ();
                        return true;
                }
               
                public void ShowLoginWindow ()
                {
                        if (_mainWindow != null) {
                                _mainWindow.Hidden = true;
                                _mainWindow.RemoveFromSuperview ();
                                _mainWindow.Dispose ();
                                _mainWindow = null;
                        }
                        _loginWindow = new UIWindow (UIScreen.MainScreen.Bounds);
                        _loginViewController = new LoginViewController ();
                        _loginWindow.RootViewController = _loginViewController;
                        _loginWindow.MakeKeyAndVisible ();
                }
               
                public void ShowMainWindow ()
                {
                        if (_loginWindow != null) {
                                _loginWindow.Hidden = true;
                                _loginWindow.RemoveFromSuperview ();
                                _loginWindow.Dispose ();
                                _loginWindow = null;
                        }
                        _mainWindow = new UIWindow (UIScreen.MainScreen.Bounds);
                        _mainNavigationController = new MainNavigationViewController ();
                        _mainWindow.RootViewController = _mainNavigationController;
                        _mainWindow.MakeKeyAndVisible ();
                }
        }


When My LoginWindow has done its jobs it just calls ShowMainWindow smth like this:

((AppDelegate)UIApplication.SharedApplication.Delegate).ShowMainWindow ();

Hope this helps.

Andy


If you reply to this email, your message will be added to the discussion below:
http://monotouch.2284126.n4.nabble.com/Getting-my-head-round-MVC-Login-type-app-tp3515200p4373150.html
To unsubscribe from Getting my head round MVC - Login type app, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

RE: Getting my head round MVC - Login type app

AndyW
one way would be to do something like this (untested):

pulbic class Session
{
        private static _currentSession;

        public string Username;

        public static Session Current
        {
                get{
                        if(_currentSession == null)
                                _currentSession = new Session();
                        return _currentSession;
                }
                set{ _currentSession = value; }
        }
}


then access like:

var username = Session.Current.Username;

Andy