iPhone開發中瞭解UIALertView和UIActionSheet應用(1)

來源:互聯網
上載者:User

iPhone開發中瞭解UIALertViewUIActionSheet應用是本文要學習的內容,主要介紹UIALertViewUIActionSheet的應用,先來看詳細內容。

1:構建一個簡單的警告框:

 
  1. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"xingchen"  
  2. message:@"message"  
  3.        delegate:nil   
  4.       cancelButtonTitle:@"OK"  
  5.       otherButtonTitles:nil];  
  6. [alert show];  
  7. [alert release]; 

這裡,僅僅是現實一個按鈕的對話方塊,以模態的形式運行。

2:當然,我們可以在一個alertView中添加多個按鈕,參考代碼如下所示:

 
  1. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"xingchen"   
 
  1.   message:@"message"  
  2.   delegate:nil   
  3.   cancelButtonTitle:@"OK"  
  4.   otherButtonTitles:@"FirstButton",@"SecondButton",  
  5.    nil];  
  6. [alert show];  
  7. [alert release]; 

3:判斷單擊來那個按鈕,並根據不同的按鈕觸發不同的事件:

alertView有一個委託(UIAlertViewDelegate),我們可以繼承他,然後調用該委託來處理事件

參考代碼

 
  1. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"xingchen"   
  2.            message:@"message" delegate:self   
  3.            cancelButtonTitle:@"OK"        
  4.            otherButtonTitles:@"FirstButton",  
  5.            @"SecondButton",nil];  
  6. [alert show];  
  7. [alert release];  
  8. //delegate   
  9. -(void)alertView:(UIAlertView *)alertView  clickedButtonAtIndex:(int)index  
  10.  
  11. {  
  12.         NSString *tt = [[NSString alloc] initWithFormat:@"%d",index];  
  13. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"xingchen"  
  14. message:tt  
  15.   delegate:self   
  16.   cancelButtonTitle:@"OK"  
  17.   otherButtonTitles:nil];  
  18. [alert show];  
  19. [alert release];  

4:手動的取消對話方塊

參考代碼:

 
  1. [alert dismissWithClickedButtonIndex:0 animated:YES]; 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.