【发布时间】:2014-01-05 03:38:11
【问题描述】:
我对 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(在身份检查器中,自定义类被命名为“Viewcontroller”) - 我已经为这个类实现了
ViewController.h和.m 文件。
- 它被称为
-
第二个视图控制器也是一个 UIViewController
- 它被称为
SWRevealViewController(在身份检查器中,自定义类被命名为“SWRevealViewController”) - 我也为这个类实现了
SWRevealViewController.h和.m 文件。
- 它被称为
【问题讨论】:
标签: ios iphone objective-c xcode uiviewcontroller