【问题标题】:The application does not always start in the main view应用程序并不总是在主视图中启动
【发布时间】:2011-11-04 13:46:34
【问题描述】:

我希望我的应用程序始终在主视图中启动。问题是,当您第一次打开应用程序时,应用程序会在主视图中启动,但如果我在重新打开应用程序时关闭应用程序,应用程序会在视图中启动我是在关闭它之前。

【问题讨论】:

    标签: iphone objective-c xcode ipad view


    【解决方案1】:

    当您按下主页按钮时,您的应用程序将暂停;它通常不会被终止。因此,当您再次启动它时,它会从之前的状态恢复。

    如果您希望您的应用程序终止,您需要在您的目标信息属性 (Info.plist) 中将“应用程序不在后台运行”设置为 YES。

    如果您想在后台运行但始终在启动时转到特定视图,则需要在 applicationDidBecomeActive: 中进行设置。

    【讨论】:

      【解决方案2】:

      所以项目plist中有一个选项。选项是“应用程序不在后台运行”,将其设置为YES。

      【讨论】:

        【解决方案3】:

        你可以像这样创建一个函数:

        - (void) dropWithViewController:(UIViewController*)vc {
            if( [vc modalViewController] ){
                [self dropWithViewController:[vc modalViewController]];
                [vc dismissModalViewControllerAnimated:NO];
            } else if( [vc isKindOfClass:[UINavigationController class]] ){
                [self dropWithViewController:[(UINavigationController*) vc topViewController]];
                UINavigationController *nc = (UINavigationController*)vc;
                for( int i=0;i<[[nc viewControllers] count]-1;i++ ){
                    [nc popViewControllerAnimated:NO];
                }
            } else if( [vc isKindOfClass:[UITabBarController class]]){
                [self dropWithViewController:[(UITabBarController*) vc selectedViewController]];
            } else {
                //you're at the last view, on return it will start going back
                return;
            }
        }
        

        然后在应用进入后台时这样调用(见 UIApplicationDelegate, - (void)applicationDidEnterBackground:(UIApplication *)application):

        - (void )dropAllViewControllers{
            UIViewController *firstViewController = [[[UIApplication sharedApplication]keyWindow] rootViewController];
            [self dropWithViewController:firstViewController];
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-04-14
          • 1970-01-01
          • 2013-01-16
          • 1970-01-01
          • 2014-10-12
          • 1970-01-01
          相关资源
          最近更新 更多