当用户启动模态视图控制器后从跳板返回时,会调用什么方法?

发布于 2025-01-04 05:50:53 字数 1122 浏览 5 评论 0原文

这个问题与这个问题非常相似,有一个例外。我没有使用普通的导航控制器启动我的默认视图控制器,而是添加了一个附加的视图控制器,它只是一个启动页面,允许我显示加载对话框/等

在主视图控制器的“viewDidLoad”中我启动了这个像这样使用“presentModalViewController”

- (void)viewDidLoad
{
    SplashPage *splashScreen = [[[SplashPage alloc] initWithNibName:@"SplashPage" bundle:nil viewControllerObj:self] autorelease];
    [self presentModalViewController:splashScreen animated:NO]; 

    [super viewDidLoad];
}

然后在我的启动视图中我做了一些事情(第一个是基本的连接检查,以确保应用程序可以访问互联网)。

第一次启动应用程序时,我在现在活动的启动视图控制器的 viewDidLoad 内进行此检查(就像这样)

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.viewController invokeConnectivityCheck];
}

问题是这样的 - 当此失败并且用户“卡在”加载屏幕预启动时(基本上) )当它们从跳板返回时,在此启动视图控制器中调用什么方法(此处支持多任务处理)?

我已尝试以下操作,但当我关闭应用程序并返回时,每个操作都没有触发

  • applicationWillEnterForeground
  • didFinishLaunchingWithOptions
  • applicationDidBecomeActive

我在这里缺少什么是 iOS5 友好的?或者,由于我在这里使用的模态方法,是否会调用主/默认视图控制器而不是启动画面?

先感谢您

This question is very similar to this one, with one exception. Instead of having a normal navigation controller launching my default view controller, I've added an additional view controller that is simply a splash page that allows me to show a loading dialog / etc

In my "viewDidLoad" of the main view controller I launch this using "presentModalViewController" like so

- (void)viewDidLoad
{
    SplashPage *splashScreen = [[[SplashPage alloc] initWithNibName:@"SplashPage" bundle:nil viewControllerObj:self] autorelease];
    [self presentModalViewController:splashScreen animated:NO]; 

    [super viewDidLoad];
}

Then inside my splash view I do a few things (the first is a basic connectivity check to ensure the app has internet access for example).

And the first time the app is launched I do this check inside the viewDidLoad of the now active splash view controller (like so)

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.viewController invokeConnectivityCheck];
}

The problem is this- when this fails and the user is "stuck" at a loading screen pre-launch (basically) what method is invoked in this splash view controller when they come back from the springboard (multitasking supported here)?

I've tried the following but each did not fire when I close the app and come back

  • applicationWillEnterForeground
  • didFinishLaunchingWithOptions
  • applicationDidBecomeActive

What am I missing here that is iOS5 friendly? Or does the main/default view controller get invoked instead of the splash because of the modal approach I'm using here?

Thank you in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

单挑你×的.吻 2025-01-11 05:50:53

当你“从跳板回来”时,appliationDidBecomeActive肯定会被调用。

文件:

调用此方法是为了让您的应用程序知道它已从
非活动到活动状态。发生这种情况是因为您的应用程序
由用户或系统启动。申请也可以返回
如果用户选择忽略中断,则进入活动状态
(例如来电或短信)
应用程序暂时处于非活动状态。

appliationDidBecomeActive will certainly be called when you are "coming back from the springboard".

Docs:

This method is called to let your application know that it moved from
the inactive to active state. This can occur because your application
was launched by the user or the system. Applications can also return
to the active state if the user chooses to ignore an interruption
(such as an incoming phone call or SMS message) that sent the
application temporarily to the inactive state.

茶花眉 2025-01-11 05:50:53

因此,看起来我使用的模式不适合导航控制器驱动(通过 appDelegate)风格的 iPhone 应用程序,因此我没有让默认/主视图控制器在 viewDidLoad 方法中处理此模式,而是将此逻辑推到了appDelegate 本身,因此它不是每个视图控制器的直接责任。

如果您打算做这样的事情,我会在 appDelegates 中调用它吗?使用当前活动视图控制器的方法(基本上我在 appDelegate 中保留状态,以便它知道视图控制器处于焦点)

- (void)applicationDidBecomeActive:(UIApplication *)application
{   
    SplashPage *splashScreen = [[[SplashPage alloc] initWithNibName:@"SplashPage" bundle:nil] autorelease];
    [[self activieViewController] presentModalViewController:splashScreen animated:NO];

    ConnectivityWebService* service = [[[ConnectivityWebService alloc] initWithAppDelegate:self] autorelease];
    [service verifyConnectivity];
}

另一个要求是在 appDelegate 中回调以关闭模式,就像这样

- (void)callBackAfterConnectivityCheck
{
    [[self activieViewController] dismissModalViewControllerAnimated:NO];
}

希望这对其他人有帮助(并不是说它直接回答了问题)-如果有人有一个合法的答案,我会对此给予认可,因为这主要是为了历史/对所使用模式的另一种看法。

So it looks like the pattern I was using didn't lend itself to the navigation controller driven (via appDelegate) style iPhone app so instead of having the default/main view controller handle this modal in the viewDidLoad method I pushed this logic off to the appDelegate itself so it's not a responsibility of each view controller directly.

If you plan to do something like this I invoke this inside the appDelegates ? method using the currently active view controller (basically I keep state in the appDelegate so it's aware of the view controller in focus)

- (void)applicationDidBecomeActive:(UIApplication *)application
{   
    SplashPage *splashScreen = [[[SplashPage alloc] initWithNibName:@"SplashPage" bundle:nil] autorelease];
    [[self activieViewController] presentModalViewController:splashScreen animated:NO];

    ConnectivityWebService* service = [[[ConnectivityWebService alloc] initWithAppDelegate:self] autorelease];
    [service verifyConnectivity];
}

The other requirement of this is a call back in the appDelegate to close the modal like so

- (void)callBackAfterConnectivityCheck
{
    [[self activieViewController] dismissModalViewControllerAnimated:NO];
}

Hope this was helpful to someone else (not that it directly answered the question) -if someone has a legit answer I'll give credit for that as this was mostly for history / another take on the pattern used.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文