[英]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.