Iphone 如何获得一个;“首次开放”-查看我的应用程序?
我试图找到一种方法,当你第一次启动应用程序时,我的程序会显示一个“设置”视图,但它不起作用 这是我的尝试。如果程序第一次打开(abfrage=false),appdelegate应该查看并打开另一个视图Iphone 如何获得一个;“首次开放”-查看我的应用程序?,iphone,objective-c,xcode,Iphone,Objective C,Xcode,我试图找到一种方法,当你第一次启动应用程序时,我的程序会显示一个“设置”视图,但它不起作用 这是我的尝试。如果程序第一次打开(abfrage=false),appdelegate应该查看并打开另一个视图 #import "TweetButtonAppDelegate.h" #import "TweetButtonViewController.h" #import "BenutzerdatenViewController.h" @implementation TweetButtonAppDele
#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];}
}
(...)
我尝试在appdelegate中构建一个if查询,但总是在“abfrage”为false时,程序只加载一个白色视图。尝试在“顶级”视图控制器中实现的方法:
- (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];
}
基本上,我认为您希望在ViewDid中执行此操作并显示在主视图控制器中。至少我是这样做的。试试这个在“顶级”视图控制器中实现的方法:
- (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];
}
基本上,我认为您希望在ViewDid中执行此操作并显示在主视图控制器中。至少我是这样做的。我得到了一个解决方案,可以在AppDelegate的ApplicationIDFinishLaunching中设置:
- (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];
}
}
我得到了一个解决方案,可以在AppDelegate的ApplicationIDFinishLaunching中设置:
- (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];
}
}
问题是您初始化了一个新的BenutzerdatenViewController,但没有将其添加到窗口中 您需要在初始化后添加:
[window addSubview: Benutzerdaten.view];
[window makeKeyAndVisible];
问题是您初始化了一个新的BenutzerdatenViewController,但没有将其添加到窗口中 您需要在初始化后添加:
[window addSubview: Benutzerdaten.view];
[window makeKeyAndVisible];
我不知道为什么,但是如果我在ViewDidDisplay或viewDidLoad中设置它,我的ViewController不会加载新视图-我知道,我的代码是正确的,因为当我将基本代码添加到UIAction时,他只需按下按钮即可加载新视图。我不知道为什么,但是我的ViewController不会加载新视图,如果我在ViewDidDisplay或viewDidLoad中设置它,我知道我的代码是正确的,因为当我将基本代码添加到UIAction时,他只需按下一个按钮即可加载新视图。