成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

iPhone開發中了解UIALertView和UIActionSheet應用

移動開發 iOS
本文介紹的是iPhone開發中了解UIALertView和UIActionSheet應用,主要是來了解他們的用法,先來看詳細內容。

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]; 

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

iPhone開發中了解UIALertView和UIActionSheet應用

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]; 

iPhone開發中了解UIALertView和UIActionSheet應用

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]; 

#p#

5:為UIAlertView添加子視圖

在為UIAlertView對象太添加子視圖的過程中,有點是需要注意的地方,如果刪除按鈕,也就是取消UIAlerView視圖中所有的按鈕的時候,可能會導致整個顯示結構失衡。 按鈕占用的空間不會消失,我們也可以理解為這些按鈕沒有真正的刪除,僅僅是他不可見了而已。如果在UIAlertview對象中僅僅用來顯示文本,那么,可以在消息的開頭添加換行符(@"\n)有助于平衡按鈕底部和頂部的空間。

下面的代碼用來演示如何為UIAlertview對象添加子視圖的方法。

  1. -(IBAction)showAlert  
  2. {  
  3. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"xingchen" message:nil delegate:nil   
  4. cancelButtonTitle:nil otherButtonTitles:nil];  
  5. [alert show];  
  6. UIActivityIndicatorView *activeView = [[UIActivityIndicatorView alloc]   
  7. initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];  
  8. activeView.center = CGPointMake(alert.bounds.size.width/2.0f, alert.bounds.size.height-40.0f);  
  9. [activeView startAnimating];  
  10. [alert addSubview:activeView];  
  11. [activeView release];  
  12. [alert release];  

顯示效果如下所示:

iPhone開發中了解UIALertView和UIActionSheet應用

6:UIActionSheet

UIActionSheet也是一個模態對話框,提供類似于菜單的功能,供用戶進行選擇,參考代碼如下所示:

iPhone開發中了解UIALertView和UIActionSheet應用 

  1. -(IBAction)showAlert  
  2. {  
  3. UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"ActionSheetTitle"  
  4.  
  5. delegate:nil  
  6.                cancelButtonTitle:@"Cancel"  
  7.   destructiveButtonTitle:nil  
  8.      otherButtonTitles:@"FirstButton",@"SecondButton",@"thirdButton",nil];  
  9. [sheet showInView:[self view]];  
  10. [sheet release];  
  11. }  
  12. [sheet showInView:[self view]];  

表示該UIActionsheet在那個視圖里面顯示。

他有一個委托是:UIActionSheetDelegate

委托的函數:

  1. @protocol UIActionSheetDelegate <NSObject> 
  2.  
  3. @optional  
  4.  
  5. // Called when a button is clicked. The view will be automatically dismissed after this call returns  
  6. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;  
  7. // Called when we cancel a view (eg. the user clicks the Home button). This is not called when the user clicks the cancel button.  
  8. // If not defined in the delegate, we simulate a click in the cancel button  
  9. - (void)actionSheetCancel:(UIActionSheet *)actionSheet;  
  10. - (void)willPresentActionSheet:(UIActionSheet *)actionSheet;   
  11.  // before animation and showing view  
  12. - (void)didPresentActionSheet:(UIActionSheet *)actionSheet;   
  13.  // after animation  
  14. - (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex;   
  15. // before animation and hiding view  
  16. - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex;  
  17.   // after animation  
  18. @end 

7:Please wait ;向用戶顯示進度。

等待是計算機用戶體驗的一個部分,iphone也需要在某些情況下告知用戶你所需要的數據正在加載過程中,請用戶耐心等待,并需要讓用戶看到iphone當前確實在運行而不是已經死機。在iphone有2中有兩種方式來達到該效果

  1. UIActivityIndicatorView 和UIActionSheet 

8:UIProgressBar

一個顯示進度的進度條控件,他可以讓用戶看到程序工作的進度,指示任務完成的程度。

9:使用網絡指示器:

  1. UIApplication *app = [UIApplication sharedApplication];  
  2. app.networkActivityIndicatorVisible = !app.networkActivityIndicatorVisible; 

小結:iPhone開發中了解UIALertViewUIActionSheet應用的內介紹完了,希望本文對你有所幫助!

責任編輯:zhaolei 來源: 博客園
相關推薦

2011-08-16 10:45:25

iPhone開發控件

2011-08-02 13:35:41

iOS開發 Get Post

2011-08-04 17:19:49

iPhone開發 Xcode 文檔

2011-07-27 17:30:40

iPhone Locate 定位

2011-08-08 10:10:14

iPhone開發 圖片 方法

2011-08-08 16:56:44

iPhone 字符處理 視圖

2011-08-10 10:10:21

iPhoneUIPopoverCo

2011-08-09 17:29:29

iPhone文件屏幕

2011-07-08 14:58:16

iPhone Xcode iOS

2011-07-19 09:46:38

2011-07-19 09:58:36

2011-08-22 15:15:49

iPhone開發NSMutableAr排序

2011-08-03 17:27:40

iPhone UIScrollVi

2011-07-28 13:59:40

iPhone App

2011-08-05 14:25:11

iPhone 架構 音頻

2011-08-05 14:48:06

iPhone應用 異步隊列

2011-08-09 13:10:32

iPhone地圖開發

2011-08-10 17:37:00

iPhoneASIHTTPRequ

2011-08-11 10:03:43

iPhonecocoaNSRunLoop

2011-08-18 10:39:46

iPhone開發界面
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产精品日本一区二区在线播放 | 黄色国产大片 | 天天久久| 国产99久久 | 国产精品久久久久久久久久久久 | 久草热8精品视频在线观看 午夜伦4480yy私人影院 | 欧美一区不卡 | 国产一区二区在线免费视频 | 一区二区激情 | 国产一区二区成人 | 男女羞羞视频免费看 | 日本在线播放 | 操久久| 精品一区二区三区四区在线 | 99免费在线观看视频 | 久久中文字幕视频 | 香蕉视频91 | 亚洲国产精品第一区二区 | 日日夜夜操天天干 | 欧美freesex黑人又粗又大 | 亚洲精品播放 | 亚洲成人黄色 | 久久久精品 | 成人a免费 | 久久综合av | 综合激情av | 国产片侵犯亲女视频播放 | 日韩一区二区三区视频 | 中文字幕国产视频 | 亚洲精品电影网在线观看 | 欧美精品一区三区 | 毛片免费在线观看 | 午夜在线 | 欧美亚洲视频在线观看 | heyzo在线 | 国产在线一区二区 | 一级做a爰片性色毛片16 | 亚洲综合久久精品 | 中文字幕成人免费视频 | 黄色在线网站 | 欧美网站一区二区 |