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:
:-)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.