Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alisoftware/ohalertview
UIAlertView subclass that uses blocks to handle its callback (which make the code much more easier and readable)
https://github.com/alisoftware/ohalertview
Last synced: about 1 month ago
JSON representation
UIAlertView subclass that uses blocks to handle its callback (which make the code much more easier and readable)
- Host: GitHub
- URL: https://github.com/alisoftware/ohalertview
- Owner: AliSoftware
- License: mit
- Created: 2013-08-08T15:25:16.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-12-23T13:41:30.000Z (almost 9 years ago)
- Last Synced: 2024-09-29T14:47:27.876Z (about 1 month ago)
- Language: Objective-C
- Size: 39.1 KB
- Stars: 16
- Watchers: 5
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![Version](http://cocoapod-badges.herokuapp.com/v/OHAlertView/badge.png)](http://cocoadocs.org/docsets/OHAlertView)
[![Platform](http://cocoapod-badges.herokuapp.com/p/OHAlertView/badge.png)](http://cocoadocs.org/docsets/OHAlertView)## About this class
This class make it easier to use Alert Views with blocks, and make the transition between `UIAlertView` (iOS < 8.0) to UIAlertController (iOS 8.0+)
This allows you to provide directly the code to execute (as a block) in return to the tap on a button,
instead of declaring a delegate and implementing the corresponding methods.This also has the huge advantage of **simplifying the code especially when using multiple `UIAlertViews`** in the same object (as in such case, it is not easy to have a clean code if you share the same delegate)
_Note: You may also be interested in [OHActionSheet](https://github.com/AliSoftware/OHActionSheet)_
## Usage Example
[OHAlertView showAlertWithTitle:@"Alert Demo"
message:@"You like this sample?"
cancelButton:@"No"
otherButtons:@[@"Yes"]
buttonHandler:^(OHAlertView* alert, NSInteger buttonIndex)
{
NSLog(@"button tapped: %d",buttonIndex);
if (buttonIndex == alert.cancelButtonIndex) {
NSLog(@"No");
} else {
NSLog(@"Yes");
}
}];
## CocoaPods
This class is referenced in CocoaPods, so you can simply add `pod OHAlertView` to your Podfile to add it to your pods.
## Compatibility Notes
* This class uses blocks, which is a feature introduced in iOS 4.0.
* This class uses ARC.
* This class internally uses `UIAlertView` if you are targeting iOS < 8.0, and use `UIAlertController` if you are targeting iOS8 or above## License
This code is under MIT License.