background image
C H A P T E R 1 7
Additional System Services
Using Additional System Services
17-9
Avoiding Undo-Related "Bad Package" Errors
17
The
AddUndoAction
method saves the current context (
self
) so that later it can
send the "redo" message (the argument to the methodName parameter of the
AddUndoAction
method) to the appropriate object. As a result, it is possible that
references to your application can stay in the system inside the Undo mechanism's
data structures after the application has been removed. These references can cause
-10401 (bad package) errors when the user taps Undo after ejecting the card on
which the application resides. Using the
EnsureInternal
function on all
parameters passed to the
AddUndoAction
function does not remedy this problem.
You can use the
ClearUndoStacks
function to clean up dangling references
to
self
that are left behind by the
AddUndoAction
method. The
ClearUndoStacks
function is generally called from the
ViewQuitScript
method of the application base view. You can call this function elsewhere as
necessary but you must do so very cautiously to avoid damaging other
applications' undo actions.
Note
The
ClearUndoStacks
function deletes all pending undo
actions--including those posted by other applications. Use this
function cautiously.
Using Idler Objects
17
This section describes how to install an idler object for a specified view. An idler
object sends
ViewIdleScript
messages to the view periodically.
Note that an idler object cannot guarantee its
ViewIdleScript
message to be
sent at precisely the time you specify. The
ViewIdleScript
message cannot be
sent until an executing method returns; thus the idler's message may be delayed if a
method is executing when the interval expires.
Using an idler object is straightforward; you need to
Send the
SetUpIdle
message to the view that is to receive the
ViewIdleScript
message. This message takes a single parameter: the
number of milliseconds to wait before sending the first
ViewIdleScript
message.
Implement the
ViewIdleScript
method that is to be executed. This method
should return the number of milliseconds before the next
ViewIdleScript
message is sent.
Call
SetUpIdle
again, this time passing in the value 0, or return
nil
from
your
ViewIdleScript
. This removes the idler object.
The idler object is removed in any case when the view is closed.
© 2007-2024, o7 studio » при воспроизведении материала сайта ссылка обязательна