自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone開(kāi)發(fā)中了解UIALertView和UIActionSheet應(yīng)用

移動(dòng)開(kāi)發(fā) iOS
本文介紹的是iPhone開(kāi)發(fā)中了解UIALertView和UIActionSheet應(yīng)用,主要是來(lái)了解他們的用法,先來(lái)看詳細(xì)內(nèi)容。

iPhone開(kāi)發(fā)中了解UIALertViewUIActionSheet應(yīng)用是本文要學(xué)習(xí)的內(nèi)容,主要介紹UIALertViewUIActionSheet的應(yīng)用,先來(lái)看詳細(xì)內(nèi)容。

1:構(gòu)建一個(gè)簡(jiǎn)單的警告框:

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

這里,僅僅是現(xiàn)實(shí)一個(gè)按鈕的對(duì)話框,以模態(tài)的形式運(yùn)行。

iPhone開(kāi)發(fā)中了解UIALertView和UIActionSheet應(yīng)用

2:當(dāng)然,我們可以在一個(gè)alertView中添加多個(gè)按鈕,參考代碼如下所示:

 

  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開(kāi)發(fā)中了解UIALertView和UIActionSheet應(yīng)用

3:判斷單擊來(lái)那個(gè)按鈕,并根據(jù)不同的按鈕觸發(fā)不同的事件:

alertView有一個(gè)委托(UIAlertViewDelegate),我們可以繼承他,然后調(diào)用該委托來(lái)處理事件

參考代碼

  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:手動(dòng)的取消對(duì)話框

參考代碼:

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

#p#

5:為UIAlertView添加子視圖

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

下面的代碼用來(lái)演示如何為UIAlertview對(duì)象添加子視圖的方法。

  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開(kāi)發(fā)中了解UIALertView和UIActionSheet應(yīng)用

6:UIActionSheet

UIActionSheet也是一個(gè)模態(tài)對(duì)話框,提供類似于菜單的功能,供用戶進(jìn)行選擇,參考代碼如下所示:

iPhone開(kāi)發(fā)中了解UIALertView和UIActionSheet應(yīng)用 

  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在那個(gè)視圖里面顯示。

他有一個(gè)委托是:UIActionSheetDelegate

委托的函數(shù):

  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 ;向用戶顯示進(jìn)度。

等待是計(jì)算機(jī)用戶體驗(yàn)的一個(gè)部分,iphone也需要在某些情況下告知用戶你所需要的數(shù)據(jù)正在加載過(guò)程中,請(qǐng)用戶耐心等待,并需要讓用戶看到iphone當(dāng)前確實(shí)在運(yùn)行而不是已經(jīng)死機(jī)。在iphone有2中有兩種方式來(lái)達(dá)到該效果

  1. UIActivityIndicatorView 和UIActionSheet 

8:UIProgressBar

一個(gè)顯示進(jìn)度的進(jìn)度條控件,他可以讓用戶看到程序工作的進(jìn)度,指示任務(wù)完成的程度。

9:使用網(wǎng)絡(luò)指示器:

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

小結(jié):iPhone開(kāi)發(fā)中了解UIALertViewUIActionSheet應(yīng)用的內(nèi)介紹完了,希望本文對(duì)你有所幫助!

責(zé)任編輯:zhaolei 來(lái)源: 博客園
相關(guān)推薦

2011-08-16 10:45:25

iPhone開(kāi)發(fā)控件

2011-08-02 13:35:41

iOS開(kāi)發(fā) Get Post

2011-08-04 17:19:49

iPhone開(kāi)發(fā) Xcode 文檔

2011-07-19 09:46:38

2011-07-08 14:58:16

iPhone Xcode iOS

2011-07-19 09:58:36

2011-07-27 17:30:40

iPhone Locate 定位

2011-08-08 16:56:44

iPhone 字符處理 視圖

2011-08-08 10:10:14

iPhone開(kāi)發(fā) 圖片 方法

2011-08-09 17:29:29

iPhone文件屏幕

2011-08-10 10:10:21

iPhoneUIPopoverCo

2011-08-22 15:15:49

iPhone開(kāi)發(fā)NSMutableAr排序

2011-07-28 13:59:40

iPhone App

2011-08-03 17:27:40

iPhone UIScrollVi

2011-08-08 14:57:46

iPhone Autoreleas Property

2011-08-09 13:10:32

iPhone地圖開(kāi)發(fā)

2011-08-11 10:03:43

iPhonecocoaNSRunLoop

2011-08-05 14:48:06

iPhone應(yīng)用 異步隊(duì)列

2011-08-10 17:37:00

iPhoneASIHTTPRequ

2011-08-18 10:39:46

iPhone開(kāi)發(fā)界面
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)