简体   繁体   English

如何获得我的应用程序的“首次打开”视图?

[英]How to get a “first time open”-view for my app?

I'm trying to find a way that my program will show up a "setup"-view, when you first start the app, but it doens´t works. 我试图找到一种方法,让您的程序在您首次启动该应用程序时显示“设置”视图,但无法正常工作。

Here is my attempt. 这是我的尝试。 The appdelegate should look, if the program opens the first time (abfrage = false) and open an other view. 如果程序是第一次打开(abfrage = false)并打开另一个视图,则appdelegate应当外观。

#import "TweetButtonAppDelegate.h"
#import "TweetButtonViewController.h"
#import "BenutzerdatenViewController.h"

@implementation TweetButtonAppDelegate

@synthesize window;
@synthesize viewController;
@synthesize abfrage;


- (void)applicationDidFinishLaunching:(UIApplication *)application {
    abfrage = FALSE;
if (abfrage == TRUE) {
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
} else {
    BenutzerdatenViewController *Benutzerdaten = [[BenutzerdatenViewController alloc] initWithNibName:nil bundle:nil];
    [Benutzerdaten release];}
}
(...)

I tried to build a if-query in the appdelegate, but always when "abfrage" is false, the program just loads a white view. 我试图在appdelegate中建立一个if-query,但是总是在“ abfrage”为false的情况下,程序仅加载白色视图。

Try this which is implemented in the "top level" view controller: 尝试在“顶层”视图控制器中实现的方法:

- (void)viewDidAppear:(BOOL)animated {
    [flasher setSettingsFromModel:self.settingsModel];
    if (self.settingsModel.warningAccepted == NO) {
        [self showWarning];
        [flasher setFlashingEnabled:NO];
    } else
        [flasher setFlashingEnabled:YES];
    [super viewDidAppear:animated];
}

...

- (void)modalViewControllerDidFinish:(UIViewController *)controller {
        if (self.settingsModel.warningAccepted == YES)
            [flasher setFlashingEnabled:YES];
        [self dismissModalViewControllerAnimated:YES];
}

...

- (void)showWarning {
        WarningViewController *controller = [[WarningViewController alloc]
                        initWithNibName:@"WarningView" bundle:nil];
        controller.delegate = self;
        controller.settingsModel = settingsModel;
            controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        [self presentModalViewController:controller animated:YES];
        [controller release];
}

Essentially I think you want to do this in viewDidAppear in your main view controller. 本质上,我认为您想在主视图控制器的viewDidAppear中执行此操作。 At least that's how I did it. 至少我是这样的。

I got a solution, which can be set in the applicationDidFinishLaunching of the AppDelegate: 我有一个解决方案,可以在AppDelegate的applicationDidFinishLaunching中进行设置:

- (void)applicationDidFinishLaunching:(UIApplication *)application {
 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    NSString *firsttime = [defaults stringForKey:@"firsttime"];
    if (firsttime == nil) {

        TheOtherViewController *Other = [[TheOtherViewController alloc] initWithNibName:nil bundle:nil];
        Other.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [window addSubview: Other.view];        

        [defaults setObject:@"lasttime" forKey:@"firsttime"];
    }   else {  [window addSubview:viewController.view];
        [window makeKeyAndVisible];
    }
}

The problem is that you initialize a new BenutzerdatenViewController, but don't add it to the window. 问题是您初始化了一个新的BenutzerdatenViewController,但没有将其添加到窗口中。

You need to add that after the initialization: 您需要在初始化之后添加它:

[window addSubview: Benutzerdaten.view];
[window makeKeyAndVisible];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何判断用户是否第一次打开我的应用程序? - How can I tell if the user opened my app for the first time? 首次启动我的应用程序时,未获得用户对推送通知警报视图的同意 - Obtaining user consent for Push notification alert view doesn't show on first time launch with my app 首次启动应用时如何获取和存储用户名和密码? - How to get and store Username and password when app is launched for the first time? iOS应用仅在首次使用该应用时发送提醒视图 - iOS app sending an alert view only on the first time using the app 如何在我的应用程序中添加“条款和条件”视图,以便仅在第一次可见 - How to add Terms and conditions view to my application so that it will be visible first time only 如何隐藏UITabBarController,直到在第一个视图上首次调用webViewdidFinishLoad为止 - How to hide a UITabBarController until the first time webViewdidFinishLoad on the first view is called 如何为我的第一个视图隐藏UINavigationBar - How to hide the UINavigationBar for my first view 如何首次在设备上测试iPhone应用程序? - How to test an iPhone app on a device for the first time? 如何检测首次在 iPhone 上启动的应用程序 - How to detect first time app launch on an iPhone 每次打开我的应用时,仅当使用者选择 - Open View everytime my app is opened, only if use chooses to
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM