Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在应用程序已启动后加载其他视图控制器_Ios_Iphone_Objective C_Xcode_Uiviewcontroller - Fatal编程技术网

Ios 在应用程序已启动后加载其他视图控制器

Ios 在应用程序已启动后加载其他视图控制器,ios,iphone,objective-c,xcode,uiviewcontroller,Ios,Iphone,Objective C,Xcode,Uiviewcontroller,我对Xcode有点陌生 我有一个问题,关于在应用程序启动后加载其他应用程序。我已经看过了以前的问题,比如我的问题,并且在appdelegate.m文件中看到了这个问题的答案,特别是did finishwithlaunchingoptions方法 然而,答案提供的代码对我来说并没有任何补救措施,因为我使用的是情节提要,从Xcode 5开始,initwithnib方法就不能再使用了 如果您不太清楚我的问题,我在appdelegate.m中的代码如下所示: - (BOOL)application:(U

我对Xcode有点陌生

我有一个问题,关于在应用程序启动后加载其他应用程序。我已经看过了以前的问题,比如我的问题,并且在
appdelegate.m
文件中看到了这个问题的答案,特别是
did finishwithlaunchingoptions
方法

然而,答案提供的代码对我来说并没有任何补救措施,因为我使用的是
情节提要
,从Xcode 5开始,
initwithnib
方法就不能再使用了

如果您不太清楚我的问题,我在
appdelegate.m
中的代码如下所示:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
 {
  // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
    {
        NSLog(@"not first launch");
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController"  bundle:nil];
        self.window.rootViewController = self.viewController;
    }
    else
    {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
        [[NSUserDefaults standardUserDefaults] synchronize];

        self.initialViewController = [[InitialViewController alloc]  initWithNibName:@"InitialViewController" bundle:nil];
        self.window.rootViewController = self.InitialViewController;
        NSLog(@"first launch");
    }
    [self.window makeKeyAndVisible];



UIImage *navBackgroundImage = [UIImage imageNamed:@"nav_bg"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];

[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
                                                       [UIColor colorWithRed:10.0/255.0 green:10.0/255.0 blue:10.0/255.0 alpha:1.0], UITextAttributeTextColor,
                                                       [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],UITextAttributeTextShadowColor,
                                                       [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                       UITextAttributeTextShadowOffset,
                                                       [UIFont fontWithName:@"Avenir Next" size:20.0], UITextAttributeFont, nil]];

UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor whiteColor];

return YES;
}
我面临代码中的错误,如下所示:

所以,我的主要问题是,我试图在我的
appdelegate.m
中的方法中实现这段代码,但我遇到了一些错误,我不知道为什么会出现这些错误

下面是我的两个视图控制器的图片,我希望它们是初始视图,也是应用程序加载一次后的视图:

如果它提供任何帮助:

  • 第一个视图控制器是
    UIViewController

    • 它被称为
      ViewController
      (在标识检查器中,自定义类被命名为“
      ViewController
      ”)
    • 我已经为这个类实现了
      ViewController.h
      和.m文件
  • 第二个视图控制器也是UIViewController

    • 它被称为
      SWRevealViewController
      (在标识检查器中,自定义类被命名为“
      SWRevealViewController
      ”)
    • 我也为这个类实现了
      SWRevealViewController.h
      和.m文件
    • 这个怎么样

      if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
          UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
      
          CustomVC *rootController = [storyboard instantiateViewControllerWithIdentifier:@"MyVC"];
          self.window.rootViewController = rootController;
          }
      else{    
          UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil];
          CustomVC *rootController = [storyboard instantiateViewControllerWithIdentifier:@"MyVC"];
          self.window.rootViewController = rootController;
          }
      
      如果您需要更多帮助,请告诉我。这个怎么样

      if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
          UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
      
          CustomVC *rootController = [storyboard instantiateViewControllerWithIdentifier:@"MyVC"];
          self.window.rootViewController = rootController;
          }
      else{    
          UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil];
          CustomVC *rootController = [storyboard instantiateViewControllerWithIdentifier:@"MyVC"];
          self.window.rootViewController = rootController;
          }
      

      如果您需要更多帮助,请告诉我


      您可以使用restorationIdentifier,它位于故事板标识符的正上方,并且是UIViewController属性

      UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                                               bundle: nil];
      MyViewController *controller = (MyViewController*)[mainStoryboard 
                      instantiateViewControllerWithIdentifier: @"<Controller ID>"];
       self.window.rootViewController = controller;
      
      UIStoryboard*mainStoryboard=[UIStoryboard情节提要,名称:@“mainStoryboard”
      束:零];
      MyViewController*控制器=(MyViewController*)[MainstryBoard
      实例化eviewcontrollerwhiteIdentifier:@“];
      self.window.rootViewController=控制器;
      


      您可以使用restorationIdentifier,它位于故事板标识符的正上方,是UIViewController属性

      UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                                               bundle: nil];
      MyViewController *controller = (MyViewController*)[mainStoryboard 
                      instantiateViewControllerWithIdentifier: @"<Controller ID>"];
       self.window.rootViewController = controller;
      
      UIStoryboard*mainStoryboard=[UIStoryboard情节提要,名称:@“mainStoryboard”
      束:零];
      MyViewController*控制器=(MyViewController*)[MainstryBoard
      实例化eviewcontrollerwhiteIdentifier:@“];
      self.window.rootViewController=控制器;
      

      @achievelimitless两个答案都对我的问题正确。谢谢你的帮助@我再提一个问题。所以字符串@“”,我是把我的故事板id还是我的恢复id?@achievelimitless这两个答案对我的问题都是正确的。谢谢你的帮助@我再提一个问题。那么字符串@“”,我是把我的故事板id还是我的恢复id放进去了?我不是故意的,你的回答也是完全可以接受的,我只是把你做的和你的if声明的条件搞混了。如果我选择使用此选项,这是否意味着我必须用条件替换If语句?我已尝试为通用应用程序提供通用代码。我的if条件检查设备是iPad还是iPhone。你不需要在这里更换你的状况。对于iPhone,如果条件执行,则为iPad,否则为1。至少你可以投票选出答案(Yaar…;)谢谢你的回答,我将尝试实现你的代码,看看它是否有效。我不能提高投票率的唯一原因是因为我没有15%的声誉。。。但是现在我有了它,我可以投票了;)我不是故意的,你的回答也是完全可以接受的,我只是把你所做的和你的if声明的条件搞混了。如果我选择使用此选项,这是否意味着我必须用条件替换If语句?我已尝试为通用应用程序提供通用代码。我的if条件检查设备是iPad还是iPhone。你不需要在这里更换你的状况。对于iPhone,如果条件执行,则为iPad,否则为1。至少你可以投票选出答案(Yaar…;)谢谢你的回答,我将尝试实现你的代码,看看它是否有效。我不能提高投票率的唯一原因是因为我没有15%的声誉。。。但是现在我有了它,我可以投票了;)