全部,
我找不到这个问题的答案。视图控制器需要在启动时显示一次。因此,当您从App Store /测试航班下载应用程序时。
我说得对,所以先运行它,没关系。 当您完成设置页面后,它将转到主页面,当您将应用程序移动到后台时,它会从中断处继续。那很好..但是......当你通过双击主页按钮并向上推应用程序来移除应用程序(ios7)时,它再次返回到设置屏幕,但它应该从它停止的地方继续。
所以在我的App代表中,我有:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSString *savedValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"SettingsShown"];
NSLog(@"%@", savedValue);
Reachability *reachability = [Reachability reachabilityWithHostname:@"www.outtonightapp.com"];
[reachability startNotifier];
NSUserDefaults *settingsscreen = [NSUserDefaults standardUserDefaults];
[settingsscreen registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],@"firstTime", nil]];
//BOOL firstTime = [settingsscreen boolForKey:@"firstTime"];
BOOL firstTime = [settingsscreen boolForKey:@"SettingsShown"];
if (!firstTime) {
//if ( firstTime==YES) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"SettingsShown"];
[[NSUserDefaults standardUserDefaults] synchronize];
self.window.rootViewController = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"SetUpNav"];
}
else
{
return YES;
}
这确实有效,直到我不得不重新创建我的设置VC ..任何建议都会很棒。
答案 0 :(得分:0)
在类似的情况下,我使用了委托模式。
假设您有初始视图控制器initialVC。并且特殊设置视图控制器(SetUpNav)仅在未设置默认值时首次运行。然后你可以做以下事情:
@protocol SetUpNavDeleagte; @interface SetUpNavViewController : UIViewController @property (strong,nonatomic) id <SetUpNavdelegate> initiator; // the rest @end @protocol SetUpNavdelegate <NSObject> -(void)setupFinished; @end
并在代码
中触发setUpNav控制器-(void)viewDidLoad
{
// Check your defaults for consistency
if (firstTime){
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main OR you SB name" bundle:nil];
UIViewController *setUpNavVC = [loginStoryboard instantiateViewControllerWithIdentifier:@"SetUpNav"];
setUpNavVC.initiator = self;
YouAppDelegateClass *appDelegate = [[UIApplication sharedApplication] delegate];
appDelegate.window.rootViewController = setUpVC;
// Here you don't need animation as I assume it is the very first screen
}
// ... the rest
}
-(void)setupFinished
{
// Here You animately restoring your initial vc.
YouAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
appDelegate.window.rootViewController = self; // This line is for device orientation sync
[UIView transitionWithView:appDelegate.window
duration:FINISH_DURATION
options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionCurveEaseInOut
animations:^{ appDelegate.window.rootViewController = self; }
completion:nil];
// setUpNav controller will be dealloced by ARC
}
[self.initator setupFinished];
在may app中,此设置工作实际上是一个单独的故事板,其中包含自己的工作流程。顺便说一句,使用这种方法,您不仅可以第一次显示它,而且只要您的应用程序的用户默认设置不正确(如果您使用设置包)。您可以在模拟,导航堆栈或弹出窗口(iPad案例)中显示它。这是一种更通用的方法。
总结:那个开始的人,他完成了。