目标:在一定时间(3秒)内显示闪屏,然后出现登录 View 以进行身份验证过程,如果身份验证成功,则转到主页(此效果由许多应用程序,例如 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.在MainViewController
中将LogInViewController
呈现为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.在LogInViewController
中将splashScreen
呈现为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];
}
问题: 显示登录 View ,但在登录 View 之前不显示启动屏幕。
我发现SplashScreen
的viewDidLoad
方法根本没有被调用。
有人可以向我解释一下并指出我在这里缺少什么吗? 欢迎所有评论。
最佳答案
执行此操作是因为您的 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];
}
关于iphone - 无法在模态视图 Controller 上执行模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12418197/