{"id":576,"date":"2018-02-23T23:40:09","date_gmt":"2018-02-23T15:40:09","guid":{"rendered":"http:\/\/60.205.208.74\/2018\/02\/23\/ios%e8%ad%a6%e5%91%8a%e5%af%b9%e8%af%9d%e6%a1%86alerts\/"},"modified":"2018-02-23T23:40:09","modified_gmt":"2018-02-23T15:40:09","slug":"ios%e8%ad%a6%e5%91%8a%e5%af%b9%e8%af%9d%e6%a1%86alerts","status":"publish","type":"post","link":"https:\/\/www.puzi7.net\/?p=576","title":{"rendered":"iOS\u8b66\u544a\u5bf9\u8bdd\u6846(Alerts)"},"content":{"rendered":"<span itemprop=\"description\"><div class=\"article-body\">\n<div class=\"article-intro\" id=\"content\">\n<h2>IOS\u8b66\u544a\u5bf9\u8bdd\u6846\u7684\u4f7f\u7528<\/h2>\n<p>\u8b66\u544a\u5bf9\u8bdd\u6846\u7528\u6765\u7ed9\u7528\u6237\u63d0\u4f9b\u91cd\u8981\u4fe1\u606f\u3002<\/p>\n<p>\u4ec5\u5728\u8b66\u544a\u5bf9\u8bdd\u6846\u89c6\u56fe\u4e2d\u9009\u62e9\u9009\u9879\u540e\uff0c\u624d\u80fd\u7740\u624b\u8fdb\u4e00\u6b65\u4f7f\u7528\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<h3>\u91cd\u8981\u7684\u5c5e\u6027<\/h3>\n<ul>\n<li>alertViewStyle<\/li>\n<li>cancelButtonIndex<\/li>\n<li>delegate<\/li>\n<li>message<\/li>\n<li>numberOfButtons<\/li>\n<li>title<\/li>\n<\/ul>\n<h3>\u91cd\u8981\u7684\u65b9\u6cd5<\/h3>\n<pre>\n- (NSInteger)addButtonWithTitle:(NSString *)title\n<\/pre>\n<pre>\n- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex\n<\/pre>\n<pre>\n- (void)dismissWithClickedButtonIndex:\n  (NSInteger)buttonIndex animated:(BOOL)animated\n<\/pre>\n<pre>\n- (id)initWithTitle:(NSString *)title message:\n  (NSString *)message delegate:(id)delegate\n  cancelButtonTitle:(NSString *)cancelButtonTitle \n  otherButtonTitles:(NSString*)otherButtonTitles, ...\n<\/pre>\n<pre>\n- (void)show\n<\/pre>\n<h3>\u66f4\u65b0 ViewController.h\uff0c\u5982\u4e0b\u6240\u793a<\/h3>\n<p>\u8ba9\u7c7b\u7b26\u5408\u8b66\u544a\u5bf9\u8bdd\u6846\u89c6\u56fe\u7684\u59d4\u6258\u534f\u8bae\uff0c\u5982\u4e0b\u6240\u793a\uff0c\u5728ViewController.h\u4e2d\u6dfb\u52a0&lt;UIAlertViewDelegate&gt;<\/p>\n<pre>\n#import &lt;UIKit\/UIKit.h&gt;\n\n@interface ViewController : UIViewController&lt;UIAlertViewDelegate&gt;{\n    \n}\n@end\n<\/pre>\n<h3>\u6dfb\u52a0\u81ea\u5b9a\u4e49\u65b9\u6cd5 addAlertView<\/h3>\n<pre>\n-(void)addAlertView{\n    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:\n    @\"Title\" message:@\"This is a test alert\" delegate:self \n    cancelButtonTitle:@\"Cancel\" otherButtonTitles:@\"Ok\", nil];\n    [alertView show];\n}\n<\/pre>\n<h3>\u6267\u884c\u8b66\u544a\u5bf9\u8bdd\u6846\u89c6\u56fe\u7684\u59d4\u6258\u65b9\u6cd5<\/h3>\n<pre>\n#pragma mark - Alert view delegate\n- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:\n  (NSInteger)buttonIndex{\n    switch (buttonIndex) {\n        case 0:\n            NSLog(@\"Cancel button clicked\");\n            break;\n        case 1:\n            NSLog(@\"OK button clicked\");\n            break;\n        \n        default:\n            break;\n    }\n}\n<\/pre>\n<h3>\u5728 ViewController.m \u4e2d\u4fee\u6539 viewDidLoad\uff0c\u5982\u4e0b\u6240\u793a<\/h3>\n<pre>\n(void)viewDidLoad\n{\n   [super viewDidLoad];\n   [self addAlertView];\n}\n<\/pre>\n<h3>\u8f93\u51fa<\/h3>\n<p>\u73b0\u5728\u5f53\u6211\u4eec\u8fd0\u884c\u8be5\u5e94\u7528\u7a0b\u5e8f\u6211\u4eec\u4f1a\u770b\u5230\u4e0b\u9762\u7684\u8f93\u51fa\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"attachment-full\" alt=\"alertOutput1\" src=\"http:\/\/www.runoob.com\/wp-content\/uploads\/2013\/11\/alertOutput1.jpg\" width=\"250\" height=\"490\" data-pinit=\"registered\"><\/p>\n<\/p><\/div>\n<\/p><\/div>\n<span>","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\"><span itemprop=\"description\">IOS\u8b66\u544a\u5bf9\u8bdd\u6846\u7684\u4f7f\u7528 \u8b66\u544a\u5bf9\u8bdd\u6846\u7528\u6765\u7ed9\u7528\u6237\u63d0\u4f9b\u91cd\u8981\u4fe1\u606f\u3002 \u4ec5\u5728\u8b66\u544a\u5bf9\u8bdd\u6846\u89c6\u56fe\u4e2d\u9009\u62e9\u9009\u9879\u540e&hellip;<\/span><\/p>\n<p class=\"more-link-p btn-align-right\"><a class=\"green zoom-btn\" href=\"https:\/\/www.puzi7.net\/?p=576\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,26],"tags":[74,93],"class_list":["post-576","post","type-post","status-publish","format-standard","hentry","category-ios","category-mobile","tag-ios","tag-mobile","zoom-theme-has-thumb"],"_links":{"self":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/576","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=576"}],"version-history":[{"count":0,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/576\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}