iphone - 无法在模态视图 Controller 上执行模态

标签 iphone ios modalviewcontroller presentmodalviewcontroller

目标:在一定时间(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 之前不显示启动屏幕。

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

有人可以向我解释一下并指出我在这里缺少什么吗? 欢迎所有评论。

最佳答案

执行此操作是因为您的 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/

相关文章:

ios - Swift - 新更新提供可选问题

macos - 如何呈现一个新的自定义 NSView(模态?)

iphone - 在 ViewController 中设置自定义 UITableViewCell 的 UILabel.text

iphone - 更改 UITextField 行为

android - Appium 和 Calabash 是否需要 root 或越狱才能在移动应用程序上进行自动化测试?

ios - 选择标签栏项目时显示模态视图

ios - 如何计算 iPad 上模态视图的底部偏移量?

iphone - 为 Android 和 iPhone 开发的 Web 框架?

iphone - 是否有图书馆或轻松的类(class)来确定用户是否使用 WiFi?

ios - 如何使用按钮动态地将单元格添加到我的 TableView 中