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

iOS中警告視圖的簡單應(yīng)用

移動(dòng)開發(fā) iOS
本文介紹了iOS中警告視圖的簡單應(yīng)用,具體講解了如何使用UIAlertView類顯示警告信息給用戶看,希望對大家有所幫助。

創(chuàng)建一個(gè)警告,具體代碼只有如下:

  1. - (void) presentSheet 
  2. UIAlertView *baseAlert = [[UIAlertView alloc] 
  3. initWithTitle:@"Alert" message:@"" 
  4. delegate:self cancelButtonTitle:nil 
  5. otherButtonTitles:@"OK", nil]; 
  6. [baseAlert show]; 

類學(xué)習(xí)

UIAlertView類

繼承UIView

Use the UIAlertView class to display an alert message to the user. An alert view functions similar to but differs in appearance from an action sheet (an instance of UIActionSheet).

使用UIAlertView類顯示警告信息給用戶看。警告視圖函數(shù)類似但不同于從動(dòng)作表上的呈現(xiàn)(UIActionSheet實(shí)例)

屬性:
delegate
title
message
visible

//這里可以看出在init方法調(diào)用的參數(shù)部分可以由屬性來設(shè)置

cancelButtonIndex:-1表示未設(shè)置.
firstOtherButtonIndex:此屬性只讀
numberOfButtons:按鈕個(gè)數(shù),只讀

方法:
– initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:
– show

– addButtonWithTitle:通過所給標(biāo)題添加按鈕
– buttonTitleAtIndex:返回指定索引下的按鈕標(biāo)題

– dismissWithClickedButtonIndex:animated:清除接收器,動(dòng)畫可選

針對UIAlertView視圖類如何響應(yīng)按鈕觸發(fā)?
這里要用到
UIAlertViewDelegate Protocol

此協(xié)議接口定義UIAlertView對象委托需要執(zhí)行的方法

Responding to Actions
    – alertView:clickedButtonAtIndex:當(dāng)用戶在警告視圖點(diǎn)擊按鈕時(shí)發(fā)送給委托處理并響應(yīng)
Customizing Behavior
    – willPresentAlertView:警告視圖呈現(xiàn)給用戶前發(fā)送給委托
    – didPresentAlertView:警告視圖呈現(xiàn)給用戶后發(fā)送給委托
    – alertView:willDismissWithButtonIndex:在警告視圖清除前發(fā)送給委托
    – alertView:didDismissWithButtonIndex:在警告視圖從屏幕離開后發(fā)送給委托
Canceling
    – alertViewCancel:在警告視圖中止前發(fā)送給委托

整體來說,警告視圖類的方法和觸發(fā)事件都非常簡單
在寫觸發(fā)事件時(shí)需要繼承<UIAlertViewDelegate>協(xié)議接口

/************************************************************/
后續(xù)一例子:自動(dòng)計(jì)時(shí)無按鈕警告
這個(gè)例子咋看是一個(gè)新的東西,仔細(xì)閱讀下代碼,就是使用NSTimer和UIAlertView
注意兩個(gè)地方:
1、創(chuàng)建警告視圖的時(shí)候,不要添加Button
2、Timer關(guān)閉警告視圖的時(shí)候,設(shè)置Repeat參數(shù)=No
參看代碼:

  1. - (void) performDismiss: (NSTimer *)timer 
  2. [baseAlert dismissWithClickedButtonIndex:0 animated:NO]; 
  3. [baseAlert release]; 
  4. baseAlert = NULL; 
  5. - (void) presentSheet 
  6. baseAlert = [[UIAlertView alloc] 
  7. initWithTitle:@"Alert" message:@"\nMessage to user with asynchronous information" 
  8. delegate:self cancelButtonTitle:nil 
  9. otherButtonTitles: nil];//注意cancelButtonTitle和otherButtonTitles都nil 
  10. [NSTimer scheduledTimerWithTimeInterval:3.0f 
  11. target:self 
  12. selector: @selector(performDismiss:) 
  13. userInfo:nil repeats:NO];//注意repeats:NO 
  14. [baseAlert show]; 

 

責(zé)任編輯:閆佳明 來源: cnblogs
相關(guān)推薦

2013-06-14 13:31:30

iOS開發(fā)移動(dòng)開發(fā)警告視圖

2011-09-02 19:12:59

IOS應(yīng)用Sqlite數(shù)據(jù)庫

2021-07-28 10:07:19

iOS 15蘋果地圖天氣

2012-05-13 13:15:54

IOS

2012-05-14 17:10:50

iOS

2011-12-28 15:11:09

iOS推薦

2024-08-08 07:13:36

2011-06-27 15:08:18

QML 視圖

2010-03-09 10:49:35

python簡單應(yīng)用

2011-01-27 09:20:11

Samba應(yīng)用案例

2009-11-17 16:47:09

Oracle物化視圖日

2011-08-17 15:10:21

iPhone開發(fā)Web視圖

2011-07-08 14:51:34

iPhone 視圖

2011-07-22 13:23:56

IOS UI ScrollView

2013-03-29 11:06:24

iOS開發(fā)滾動(dòng)視圖UIScrol

2014-04-23 13:30:23

類簇iOS開發(fā)

2015-01-20 17:15:55

iOS源碼滾動(dòng)視圖

2010-05-18 14:21:35

MySQL視圖

2015-05-13 09:15:50

應(yīng)用程序開發(fā)PaaSAWS

2009-05-06 11:09:10

Oracle物化視圖數(shù)據(jù)庫
點(diǎn)贊
收藏

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