applicationShouldTerminate在iPhone上的问题 [英] Problem with applicationShouldTerminate on iPhone

查看:210
本文介绍了applicationShouldTerminate在iPhone上的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了applicationShouldTerminate的问题。

I'm having a problem with applicationShouldTerminate.

我做的任何接缝都没有效果。任何帮助都是
赞赏。

What ever I do it seams that has no effect. Any help would be appreciated.

我非常精通编程,但这让我很头疼。我在xcode的一些基本教程上花了
,因为我一般都是mac的新手,目前我正在寻找一个简单的手电筒应用程序。

I'm well versed in programing but this just gives me headache. Im going over some basic tutorials for xcode , as I'm new to mac in general, and am currently looking at a simple flashlight app.

它存在但我想在这里添加一个警告框,选项不要
退出。

It exists but I would like to add a alert box here with option not to quit.

(void)applicationWillTerminate:(UIApplication *)application
{
    [application setIdleTimerDisabled:NO];
}

这没有任何效果,警报甚至在创建之前就已关闭。

this has no effect, alert is closed even before its created.

(void)applicationWillTerminate:(UIApplication *)application
{
    [application setIdleTimerDisabled:NO];
    UIAlertView *alertTest = [[UIAlertView alloc]
                          initWithTitle:@"This is a Test"
                          message:@"This is the message contained
                          with a UIAlertView"
                          delegate:self
                          cancelButtonTitle:@"Button #1"
                          otherButtonTitles:nil];

    [alertTest addButtonWithTitle:@"Button #2"];
    [alertTest show];
    [alertTest autorelease];

    NSLog(@"Termination");
}

我在网上做了一些阅读,发现应该可以做
this with

I did some reading online and found that it should be possible to do this with

(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender

但是我没有把这个声明放在哪里我得到错误:语法错误
在NSApplicationTerminateReply之前。

But no mater where I put that declaration I get error: syntax error before NSApplicationTerminateReply.

除了xcode似乎没有将
NSApplicationTerminateReply识别为有效输入之外,没有语法错误。

There is no syntax error except that xcode seems not to recognize NSApplicationTerminateReply as valid input.

我们非常感谢任何示例代码。

Any sample code would be greatly appreciated.

推荐答案


  1. 在iPhone上不存在applicationShouldTerminate和NSApplication。您必须使用UIApplication。

  1. applicationShouldTerminate and NSApplication do not exist on the iPhone. You have to use UIApplication.

警报视图永远不会显示,因为'show'方法不会阻止,因此'applicationWillTerminate'的结尾是创建警报视图后立即到达并尝试显示它。我相信这是设计的。您无法在'applicationWillTerminate'中真正开始异步操作。

The alert view is never shown because the 'show' method does not block, and therefore, the end of 'applicationWillTerminate' is reached immediately after you create the alert view and try to show it. I believe this is by design. You can't really begin asynchronous operations in 'applicationWillTerminate'.

这篇关于applicationShouldTerminate在iPhone上的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆