Cocoanetics/DTFoundation — pull request #73 by rsanchezsaez (2014-07-23 22:15:29+00:00)
Title: DTActionSheet & DTAlertView working on iOS 6, 7 & 8

Hi,

I've seen both pull requests for issues #67 and #68. I think that both present minor problems and I'm offering my alternate solution.

#67 has some duplicated between in `-init` and `-initWithTitle:message` which makes it difficult to maintain, and breaks the *designated initializer* convention.

#68 is a little bit better because it keeps the *core* code on `init`, making it the designated initializer. However, with this solution `DTAlertView` won't work on iOS 8 if you use iOS' default `-initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:` initializer (as `init` never gets called in that case).

My solution is an extension and cleanup of #68 by adding code so `-initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:` calls `self init`, which in turn sets up the `_actionsPerIndex` blocks dictionary and delegate correctly.

I also fixed `DTActionSheet`'s which presented exactly the same problem.

In addition, I moved the block execution of `DTAlertView` from `-alertView:didDismissWithButtonIndex:` to `-alertView:clickedButtonAtIndex:` which is the correct method to execute the action (same issue as the one you merged already for `DTActionSheet`).

Finally, I added updated examples of both to the `DTProgressHUD` demo; improved the `DTAlertView` unit test to cover the three initializers I mentioned; and added a similar `DTActionSheet` unit test.

I've successfully tested this code on iOS 6, 7 and 8.

Please note that `UIActionSheet` and `UIAlertView` will be deprecated on *iOS 8*. They are both replaced by `UIAlertController` (which sadly still doesn't support blocks, lazy Apple!). So it may be a good idea to do a simple block-based `DTAlertController` class in the future (it should be pretty much the same as the current two).