0

Goal : show a splash screen in certain of time (3 seconds ) then log-in view appears for authentication process and if this authentication is successful, go to main page ( this effect is used by many applications such as facebook )

What I am doing is

1.set the root of navigation to be MainViewController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  self.isLogIn = FALSE;
  self.window  =   [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  MainViewController    *mainView      =   [[MainViewController alloc]   initWithNibName:@"MainViewController" bundle:nil];
  self.navigationController            =   [[UINavigationController alloc] initWithRootViewController:mainView];
  self.window.rootViewController       =   navigationController;
  [self.window makeKeyAndVisible];
  return YES;

}

2.Present LogInViewController as modalViewController in MainViewController

@implementation MainViewController
-(void) viewDidLoad {
  appDelegate                        =   [[UIApplication sharedApplication] delegate];
  LogInController   *logInController =   [[LogInController alloc]                 initWithNibName:@"LogInController"      bundle:nil];

  if ( !appDelegate.isLogIn )
     [self presentModalViewController:logInController animated:NO]; 
}

3.Present splashScreen as modalViewController in LogInViewController

#implementation LogInViewController
-(void)viewDidLoad
{
    [super viewDidLoad];
    self.title                     =   @"Sign in";
    SplashScreen *splashController =   [[SplashScreen alloc]           initWithNibName:@"SplashScreen"         bundle:nil];

    [self presentModalViewController:splashController animated:NO];
    ;
}

}

4.In splashScreen, dismiss itself after certain of time

@implementation SplashScreen
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self performSelector:@selector(removeSplashScreen) withObject:nil afterDelay:6.0];                         

}

-(void)removeSplashScreen{
    [self dismissViewControllerAnimated:YES completion:nil];
} 

Problem : the log in view is shown but a splashScreen is not presented before log in view.

I found out that the method of viewDidLoad of SplashScreen is not invoked at all.

Can somebody explain it to me and point out what I am missing here. All comments are welcomed here.

4

1 回答 1

1

这样做是因为您的 appDelegate 的参考存在问题

@implementation MainViewController
-(void) viewDidLoad {
   appDelegate                        =   (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
   LogInController   *logInController =   [[LogInController alloc]                 initWithNibName:@"LogInController"      bundle:nil];

   if ( !appDelegate.isLogIn )
   [self presentModalViewController:logInController animated:NO]; 
 }
于 2012-09-14T04:42:37.143 回答