1

信息

我正在使用 Storyboard 添加视图。在我的故事板中,我有 1 个视图控制器和 1 个标签栏控制器。

我想要完成的是检查用户是否是第一次使用我的程序,如果是这样,它不会显示标签栏控制器,而是显示初始视图控制器。

这是我的代码,其中包含 [self presentViewController..] 处的 AppDelegate.m 中的错误。

我的标签栏控制器的情节提要 ID 是“TabBarController”。

请注意 ViewController.h 和 ViewController.m 是 UNTOUCHED。

代码

全球标头.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(我不熟悉)更容易使用。

4

2 回答 2

2

我认为,而不是呈现标签栏控制器

[self presentViewController:TabBarController animated:YES completion:nil];

您应该将其设置为根视图控制器(因为您永远不会返回到初始视图控制器)。

self.window.rootViewController = TabBarController;
于 2013-11-11T02:44:51.750 回答
1

更好的方法是在两种情况下都加载 tabbarcontroller,检查用户是否第一次在 tabbarcontroller 的第一个视图控制器中运行应用程序,然后从内部显示视图控制器

于 2013-11-11T02:55:20.817 回答