Features:
-show
和 -dismiss
, 不需要考慮從哪個 view controller present 的問題;Known issues:
NSObject
, 無法當做普通的 view controller 使用 (下個版本修改).https://github.com/Elethom/PRAlertController
Alert controller with the same APIs as iOS 8 SDK (text field not supported), compatible with iOS 7.
In your Podfile
:
pod 'PRAlertController'
It has exactly the same APIs as iOS 8 SDK does except the text field part. Besides, with -show
, -dismiss
methods you can pop up alerts wherever you want without having to worry about how to get current view controller's pointer.
Example:
PRAlertController *alertController = [PRAlertController alertControllerWithTitle:@"Title"
message:@"This is the message."
preferredStyle:PRAlertControllerStyleAlert];
PRAlertAction *firstAction = [PRAlertAction actionWithTitle:@"First"
style:PRAlertActionStyleDefault
handler:^(PRAlertAction *action) {
[self doFirstAction];
}];
PRAlertAction *secondAction = [PRAlertAction actionWithTitle:@"Second"
style:PRAlertActionStyleDefault
handler:^(PRAlertAction *action) {
[self doSecondAction];
}];
PRAlertAction *destructiveAction = [PRAlertAction actionWithTitle:@"Destructive"
style:PRAlertActionStyleDestructive
handler:^(PRAlertAction *action) {
[self doDestructiveAction];
}];
PRAlertAction *cancelAction = [PRAlertAction actionWithTitle:@"Cancel"
style:PRAlertActionStyleCancel
handler:^(PRAlertAction *action) {
[self doCancelAction];
}];
[alertController addAction:firstAction];
[alertController addAction:secondAction];
[alertController addAction:destructiveAction];
[alertController addAction:cancelAction];
[alertcontroller show];
Easy as it seems.
This code is distributed under the terms and conditions of the MIT license.
You can support me by:
:-)
1
yellowV2ex 2014-11-01 16:43:09 +08:00
输入帐号密码或文本的那种alert怎么写?
|
10
Elethom OP |
12
Esay 2014-11-03 17:06:29 +08:00
酷,给你补个截图(代码最后一行的 Controller 大小写写错了)
|