开发者

Over-riding NSObject and adding a class variable

I am using the following code to perform a selector after a开发者_如何学C delay with multiple passed parameters:

http://nifty-box.com/blog/2006/12/nsinvocation-cleans-code.html

It works very well, but I need to extend this to support the equivalent of:

[NSObject cancelPreviousPerformRequestsWithTarget:self]

(target in this case would not be self, but would be an instance of _UFLatePerformer I believe)

Is there any way to do this, so my view's deallocation can kill all remaining delayed performance requests?


On the mac you would be able to use objc_setAssociatedObject, but that does not exist on the iPhone.

So basically you need some kind of manager singleton that holds onto these references for you that you pass in an NSObject and it does what you want.

When I was doing something similar I wrote a singleton class that took in requests to perform an action, and started a timer that fired when the action was to be done - at that time my manager class decided if the request in question was still valid, and if so fired the action. I could thus effectively cancel a timer, and furthermore could tell the manager to reset the timer which didn't really, it just made a new timer but when the old timer fired the action it was requested to perform was invalid.

So basically the timer was calling the singleton back with just a request ID, which led to a dictionary entry containing details of the call.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜