ios7_如何?UIAlertView以及監聽點擊事件(預設樣式)

來源:互聯網
上載者:User

ios7_如何?UIAlertView以及監聽點擊事件(預設樣式)
1、在viewController的.m檔案,遵守<UIAlertViewDelegate>代理協議 @interface moboViewController () <UIAlertViewDelegate>  2、在 - (void)viewDidLoad 方法中實現UIAlertView 複製代碼 1 - (void)viewDidLoad 2 { 3     [super viewDidLoad]; 4      5   // 1、初始化 alertView 6   UIAlertView *altView = [[UIAlertView alloc]initWithTitle:[self altTitle] message:[self altMSG] delegate:self cancelButtonTitle:[self cancelBtnTitle] otherButtonTitles:[self otherBtnTitle], nil]; 7     // 2、顯示 alertView 8     [altView show]; 9     10 }複製代碼  3、繼續實現其它方法,返回各種標題以及監聽按鈕點擊事件的代理方法 複製代碼 1 //返回 標題 2 - (NSString *)altTitle{ 3     return @"下線通知"; 4 } 5  6 //返回 訊息體 7 - (NSString *)altMSG{ 8     return @"你的帳號在異地登入,密碼可能泄露,建議前往http://mobodemy.com進行修改。"; 9 }10 11 //返回 退出按鈕 標題12 - (NSString *) cancelBtnTitle {13     return @"退出";14 }15 16 //返回 重新登入 按鈕標題17 - (NSString *) otherBtnTitle {18     return @"重新登入";19 }20 21 //監聽點擊事件 代理方法22 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex23 {24     NSString *btnTitle = [alertView buttonTitleAtIndex:buttonIndex];25     if ([btnTitle isEqualToString:[self cancelBtnTitle]]) {26         NSLog(@"你點擊了退出");27     }28     else if ([btnTitle isEqualToString:[self otherBtnTitle]] ) {29         NSLog(@"你點擊了重新登入按鈕");30     }31 }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.