在iPhone中真正模态UIAlertView? [英] Truly modal UIAlertView in iPhone?

查看:96
本文介绍了在iPhone中真正模态UIAlertView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要执行一些取决于用户决定的验证(例如,如果批准购买超过支出限额),如果失败,则拒绝完成操作。



但是,看起来像是不可能有一个真正的模态操作像其他语言(如showmessage,alert()等),一切都是由代表。



但是我不知道该怎么办。如果用户按下完成按钮,程序会询问你确定吗?并且他说取消的流程继续,视图被推回!



在可可世界如何解决这个问题?

解决方案是不打它,只是把你的逻辑分成两个部分。如果用户单击取消,请不要执行第二部分。如果用户单击确定/继续,执行第二部分。



阻塞主线程导致的主要问题是主线程是什么处理事件。处理事件的经典方式可能会引入奇怪的事件处理错误,因为您没有一个事件循环,而是有多个事件循环嵌入其中。



通过使用代理,您可以利用一个事件循环(通过UIApplicationMain调用),并且不会有任何这些事件处理异常。


I'm need run a couple of validations that depend on the decisions of the user (for example, if approve 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 languages (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 asks "Are you sure of this?" and he says "cancel" the flow continues and the view is pushed back!

How is solved this in the cocoa world?

解决方案

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.

这篇关于在iPhone中真正模态UIAlertView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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