国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

(轉)UIALertView的基本用法與UIAlertViewDelegate對對話框的事件處理方法

2019-11-14 19:22:23
字體:
來源:轉載
供稿:網友
首先,視圖控制器必須得實現協議UIAlertViewDelegate中的方法,并指定delegate為self,才能使彈出的Alert窗口響應點擊事件。具體代碼如下:
#import <UIKit/UIKit.h>@interface ViewController : UIViewController<UIAlertViewDelegate>@end

ViewController.m中的詳細代碼:

- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view from its nib        //初始化AlertView    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"AlertViewTest"                                                   message:@"message"                                                  delegate:self                                         cancelButtonTitle:@"Cancel"                                         otherButtonTitles:@"OtherBtn",nil];    //設置標題與信息,通常在使用frame初始化AlertView時使用    alert.title = @"AlertViewTitle";    alert.message = @"AlertViewMessage";        //這個屬性繼承自UIView,當一個視圖中有多個AlertView時,可以用這個屬性來區分    alert.tag = 0;    //只讀屬性,看AlertView是否可見    NSLog(@"%d",alert.visible);    //通過給定標題添加按鈕    [alert addButtonWithTitle:@"addButton"];    //按鈕總數    NSLog(@"number Of Buttons :%d",alert.numberOfButtons);    //獲取指定索引的按鈕標題    NSLog(@"buttonTitleAtIndex1:%@",[alert buttonTitleAtIndex:1]);    NSLog(@"buttonTitleAtIndex2:%@",[alert buttonTitleAtIndex:2]);    //獲取取消按鈕的索引    NSLog(@"cancelButtonIndex:%d",alert.cancelButtonIndex);    //獲取第一個其他按鈕的索引    NSLog(@"firstOtherButtonIndex:%d",alert.firstOtherButtonIndex);    //顯示AlertView    [alert show];    [alert release];}#PRagma marks -- UIAlertViewDelegate --//根據被點擊按鈕的索引處理點擊事件-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{    NSLog(@"clickButtonAtIndex:%d",buttonIndex);}//AlertView已經消失時執行的事件-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{    NSLog(@"didDismissWithButtonIndex");}//ALertView即將消失時的事件-(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex{    NSLog(@"willDismissWithButtonIndex");}//AlertView的取消按鈕的事件-(void)alertViewCancel:(UIAlertView *)alertView{    NSLog(@"alertViewCancel");}//AlertView已經顯示時的事件-(void)didPresentAlertView:(UIAlertView *)alertView{    NSLog(@"didPresentAlertView");}//AlertView即將顯示時-(void)willPresentAlertView:(UIAlertView *)alertView{    NSLog(@"willPresentAlertView");}- (void)viewDidUnload{    [super viewDidUnload];    // Release any retained subviews of the main view.    // e.g. self.myOutlet = nil;}

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 林州市| 通州市| 新野县| 嘉荫县| 新晃| 诸暨市| 丰原市| 金山区| 宜君县| 临城县| 延寿县| 长汀县| 绥宁县| 黄山市| 华池县| 高台县| 威信县| 开平市| 固阳县| 金堂县| 宣城市| 庆阳市| 衢州市| 隆回县| 即墨市| 云霄县| 钟山县| 彩票| 天柱县| 凭祥市| 东港市| 东辽县| 三门县| 东丽区| 盐亭县| 黎川县| 龙井市| 临洮县| 环江| 饶河县| 锡林郭勒盟|