UIAlertViewDelegate clickedButtonAtIndex:有用吗?

Ed *_*rty 12 iphone cocoa-touch

UIAlertViewDelegate协议定义了两种方法,alertView:clickedButtonAtIndex:并且 alertView:didDismissWithButtonIndex:,这似乎我是在有用性是相同的.

为什么会出现clickedButtonAtIndexdidDismissButtonWithIndex当他们都做同样的事情?我意识到willDismissButtonWithIndex在警报视图被解除之前还会发生这种情况,但有没有理由使用clickedButtonAtIndex而不是didDismissButtonWithIndex

Ed *_*rty 19

我发现两者之间有一个更有用的区别:

当显示a UIAlertView,并且设备进入睡眠状态alertView:didDismissWithButtonAtIndex:时,即使警报视图实际上没有被解除,也会被调用.一旦设备唤醒,它将再次显示. alertView:clickedButtonAtIndex:仅在用户单击其中一个按钮时调用.


Yan*_*iot 12

alertView:clickedButtonAtIndex:当用户点击一个警报视图,而一个按钮被称为alertView:didDismissWithButtonIndex:警报视图从屏幕驳回之后被调用.(请参阅UIAlertViewDelegate协议参考.)

差异很小但它允许你在动画之前或之后做一些事情.

  • willDismissWithButtonIndex方法看起来与clickedButtonAtIndex完全相同:那么...... (2认同)