【发布时间】:2013-11-22 17:04:02
【问题描述】:
信息
我正在使用 Storyboard 添加视图。在我的故事板中,我有 1 个视图控制器和 1 个标签栏控制器。
我想要完成的是检查用户是否是第一次使用我的程序,如果是这样,它不会显示标签栏控制器,而是显示初始视图控制器。
这是我的代码,其中包含 [self presentViewController..] 处的 AppDelegate.m 中的错误。
我的标签栏控制器的情节提要 ID 是“TabBarController”。
请注意 ViewController.h 和 ViewController.m 是 UNTOUCHED。
代码
GlobalHeader.h
#ifndef dirt_GlobalHeader_h
#define dirt_GlobalHeader_h
BOOL RegisterCheck;
#endif
AppDelegate.h
#import <UIKit/UIKit.h>
#import "GlobalHeader.h"
#import "ViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m
#import "AppDelegate.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
RegisterCheck = [[NSUserDefaults standardUserDefaults] boolForKey:@"RegisterCheck"];
if (!RegisterCheck)
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"RegisterCheck"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
UIStoryboard *MainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *TabBarController = [MainStoryBoard instantiateViewControllerWithIdentifier:@"TabBarController"];
[self presentViewController:TabBarController animated:YES completion:nil];
}
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
感谢任何人对我的问题做出任何贡献。
我还想说,Visual Studio IDE 比这个 XCODE(我不熟悉)更容易使用。
【问题讨论】:
-
顺便说一句,您的问题的解决方案可能最好在默认初始
viewController的viewDidLoad方法中处理,特别是如果您打算在显示 1-time 后返回此问题,第一次的场景。 -
如果用户之前没有使用过该程序,那么初始视图控制器将是注册页面,那么代码不应该在 AppDelegate 中吗?
-
您声明要向第一次使用的用户显示标签栏控制器,但您的代码正试图向现有用户显示它。你能澄清哪一个是正确的吗?
-
哦,我的坏蒂莫西穆斯,让我澄清一下(我没有注意到我的打字错误)。我希望标签栏控制器显示给现有用户,视图控制器只显示给新用户(因此代码)。
标签: ios cocoa-touch uiviewcontroller storyboard