Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delayed call, with possibility of cancelation?

How do I trigger a delay, let's say I want to call a method (once) in 3 seconds from now, and how do I cancel that call if I need to?

like image 687
Steph Thirion Avatar asked Dec 03 '08 14:12

Steph Thirion


People also ask

What is the difference between delayed and Cancelled?

A flight delay is when an airline flight takes off and/or lands later than its scheduled time. The Federal Aviation Administration (FAA) considers a flight to be delayed when it is 15 minutes later than its scheduled time. A cancellation occurs when the airline does not operate the flight at all for a certain reason.

How do I inform the cancellation of an event?

We regret to inform you that our ______________ (name of event) at _______________ (venue) on ________________ (date) has been ______________ (cancelled or postponed). We made this difficult decision to ___________ (postpone or cancel) because of _________________ (reason for cancellation or postponement).

What do you say when an event is Cancelled?

Write an apology for the cancellation of event in your email“We are sorry to inform you”, “On behalf of committee/organization I apologize”, “Please accept our sincere apologies” and so on.


2 Answers

You can also use -[NSObject performSelector:awithObject:afterDelay:], and +[NSObject cancelPreviousPerformRequestsWithTarget:selector:object].

like image 64
Ben Gottlieb Avatar answered Oct 10 '22 05:10

Ben Gottlieb


Use NSTimer. Use this to set up a call to method in three seconds time. It will only be called once:

   [NSTimer scheduledTimerWithTimeInterval: 3
                                    target: self
                                  selector: @selector(method:)
                                  userInfo: nil
                                   repeats: NO];

method needs to look like this:

- (void) method: (NSTimer*) theTimer;

You can pass parameters into the method using userInfo (set to nil in the above example). It can be accessed in the method as [theTimer userInfo].

Use the invalidate method on NSTimer to cancel it.

like image 35
Stephen Darlington Avatar answered Oct 10 '22 04:10

Stephen Darlington