views:

1893

answers:

3

I'm need run a couple of validatins that depend on the decisions of the user (for example, if aprove a purchase above the spending limit), and deny the "done" action if it's fail.

However, look like is not possible have a truly modal action like with other languajes (like showmessage, alert(), etc) and everything is by delegates.

But then I don't know what to do. If the user push the "done" button, the program ask "Are you sure of this?" and he say "cancel" the flow continue and the view is pushed back!.

How is solved this in the coccoa world?

+4  A: 

The solution is not to fight it, just break up your logic into two parts. If the user clicks cancel, do not execute the second part. If the user clicks OK/Continue, execute the second part.

The main problem caused by blocking the main thread is that the main thread is what handles events. The classic way of handling events can introduce strange event handling bugs, because you don't have one event loop, instead you have multiple event loops embedded inside of one another.

By using delegates, you can utilize one event loop (invoked via UIApplicationMain), and not have any of these event handling oddities crop up.

NilObject
A: 

OK I am trying not to fight this, but if I have to put all the logic in the second part (ie in the delegate) what do I do about passing all the variables that I need from the first part into the delegate. It seems really cludgy to have to declare all the variables at the class level or to have to pass them to the delegate, which I don't know how to do. How is this more elegant than a simple pop up that waits for a response before it continues on the main thread. Like I said I am trying not to fight it and learn the right way, but how do I deal with the variable issue.

A: 

Keep the state of the application in somewhere else other than the variables in the function. For instance, in one of my apps, there is a profile string that states whether or not they've agreed to the privacy policy.

Michael Langford