scheduledTimerWithTimeInterval vs performselector with iOS 5.0延迟 [英] scheduledTimerWithTimeInterval vs performselector with delay with iOS 5.0

查看:138
本文介绍了scheduledTimerWithTimeInterval vs performselector with iOS 5.0延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用scheduledTimerWithTimeInterval进行函数调用。我只是检查特定Web服务的xml解析是否已完成,并在获得成功响应后在didEndElement方法中使计时器失效。

i am doing function call with scheduledTimerWithTimeInterval. i am just checking that xml parsing is completed or not for particular web services and invalidating timer in didEndElement method after getting successful response.

timerForStopWebService = [NSTimer scheduledTimerWithTimeInterval:30.0 target:self selector:@selector(stopWS) userInfo:nil repeats:NO];

现在我面临iOS 5.0的问题,并且在其他iOS版本中工作正常。在iOS 5.0中,即使我使其无效,也可以随时调用函数stopWS。如果你有解决方案,请告诉我。

now i am facing problem with iOS 5.0 and its working fine in other iOS versions. in iOS 5.0, a function stopWS call anytime even if i am invalidating it. let me know if you have solution for that.

现在我正在实现带延迟的performselector并在stopWS中设置boolean变量以确定解析是否已完成。我只是想知道这有什么重大区别吗?这个解决方案适用于我的问题吗?

and now i am implementing performselector with delay and set boolean variables in stopWS to identify that parsing is completed or not. i just want to know that is there any major difference between this? and does this solution works for my problem?

如果存在其他方式,请建议我,谢谢。

if other way exists, please suggest me, thanks.

推荐答案

以下是您与众不同之处

performSelectorWithObjectAfterDelay

performSelectorWithObjectAfterDelay


  • 顾名思义,在指定的秒数后执行选择器。的 ONCE 即可。

需要注意的是,在释放执行选择器的对象之前,您需要取消之前的任何执行请求。为此使用cancelPerformSelector方法。

The care that you need to take here is that you need to cancel any previous perform requests before the object that the selector is being performed on is released. For that use the cancelPerformSelector method.

scheduledTimerWithTimeInterval

scheduledTimerWithTimeInterval


  • 此方法使您能够在指定的持续时间后调用选择器,但它还有一个参数[repeats:],可让您调用相同的选择器重复

您还可以将调用传递给调用选择器,这在选择器需要大量参数时特别有用。

You can also pass in invocations to call selectors, which are specially helpful when your selector needs a lot of arguments.

当不再需要计时器时,您需要使计时器无效。这应该可以做到这一点

You need to invalidate the timer when its no longer needed. This should do the trick

[myTimer invalidate]; myTimer = nil;

[myTimer invalidate]; myTimer = nil;

这也是NSTimer上最权威的主题,请看一下。 如何使用NSTimer?

Also this is the most definitive thread on NSTimer, please have a look at it. How do I use NSTimer?

这篇关于scheduledTimerWithTimeInterval vs performselector with iOS 5.0延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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