我对Xcode有点新。已经启动应用程序后加载不同的视图控制器
我有一个关于加载不同的应用程序已经启动的问题。我已经查看了过去的问题,例如我的问题,并看到appdelegate.m
文件中的答案,特别是didFinishWithLaunchingOptions
方法。
但是,答案所提供的代码对我来说已经证明没有补救办法,因为我使用的是storyboard
,从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
(在身份检查器中的自定义CLAS s被命名为“Viewcontroller
”) - 我已经为此类实现了
ViewController.h
和.m文件。
- 它被称为
第二个视图控制器也是一个UIViewController
- 这就是所谓
SWRevealViewController
(在身份检查器中的自定义类被命名为“SWRevealViewController
”) - 我已经实现
SWRevealViewController.h
和.m文件对于这个班级也是如此。
- 这就是所谓
@achievelimitless这两个答案对我的问题都是正确的。谢谢您的帮助! –
@iDev只是一个问题。所以字符串@“<控制器ID>”,我把我的故事板ID或我的恢复ID? –