不能在模态视图控制器上做模态

时间:2012-09-14 04:35:39

标签: iphone ios modalviewcontroller presentmodalviewcontroller

目标:在某段时间(3秒)显示启动画面,然后显示登录视图以进行身份​​验证过程,如果此身份验证成功,请转到主页(此效果由许多应用程序,如Facebook)

我正在做的是

1.将导航根设置为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.在LogInViewController

中创建MainViewController作为modalViewController
@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.在splashScreen

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

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

}

4.在splashScreen中,在某段时间后自行解散

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

}

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

问题: 显示登录视图,但在登录视图之前不显示splashScreen。

我发现根本没有调用viewDidLoad SplashScreen的方法。

有人可以向我解释并指出我在这里缺少的东西。 欢迎所有评论。

1 个答案:

答案 0 :(得分: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]; 
 }