【问题标题】:can not do modal on modal view controller不能在模态视图控制器上做模态
【发布时间】:2012-09-14 04:35:38
【问题描述】:

目标:在一定的时间(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];
} 

问题: 显示登录视图,但在登录视图之前未显示启动画面。

我发现SplashScreenviewDidLoad的方法根本没有被调用。

有人可以向我解释一下,并指出我在这里缺少什么。 这里欢迎所有的cmets。

【问题讨论】:

  • SplashScreen 是否出现在屏幕上?
  • no splashScreen 根本不出现
  • 我也遇到过这类问题。如此之多,以至于我决定在 SO 上发布我的答案。希望这会有所帮助:stackoverflow.com/questions/11697747/…
  • 感谢您的帖子,但在继续之前,我需要知道我在这里做错了什么

标签: iphone ios modalviewcontroller presentmodalviewcontroller


【解决方案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]; 
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多