ios學習筆記 UIAlertView

2021-06-18 08:26:00 字數 1582 閱讀 3829

uialertview *view=[[uialertview alloc] initwithtitle:@"標題" message:@"內容" delegate:nil cancelbuttontitle:@"取消" otherbuttontitles:@"確定", nil];

view.alertviewstyle=uialertviewstyledefault;

view.tag=1;

[view show];

[view release];

顯示介面如下:

引數說明:

initwithtitle:顯示在頂端的標示

message:顯示的內容

delegate:用來相應提醒的物件,一般設定為self,如果不執行任何操作的話,可設定為nil

cancelbuttontitle:檢視中預設按鈕標題

otherbuttontitls:檢視中其他按鈕標題,是乙個陣列,以nil結尾

uialertviewstyledefault      預設的樣式,不包含任何文字框

uialertviewstyleplaintextinput           有乙個常規文字輸入框

uialertviewstylesecuretextinput        乙個密碼輸入框

uialertviewstyleloginandpasswordinput     乙個常規文字框與密碼文字框

view.tag  假如程式中有多個uialertview時,我們可以使用這個來標識具體是那乙個

下面我們來看delegate引數,他指明有哪個類來響應使用者的操作或者讀取文字框的內容。響應類必須遵守uialertviewdelegate協議。

使用的時候首先在標頭檔案(.h)裡宣告尊送uialertviewdelegate協議。宣告如下:

@inte***ce myviewcontroller:uiviewcontroller-(void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex;

-(ibaction)myuialertview;

@end

這樣就完成了宣告。然後我們去實現它

-(void)myuialertview
如果要響應使用者的操作的話,我們可以實現:

- (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex

[ [alertview textfieldatindex:0] text]//如果有文字框的話,可以使用此方法獲取文字框的內容

}

IOS學習筆記

uiview beginanimations view flip context nil 設定動畫塊 uiview setanimationduration 1.25 動畫時間 uiview setanimationcurve uiviewanimationcurveeaseinout 動畫曲線 u...

ios學習筆記

actionsheet 標頭檔案裡加協議。ibaction buttonpressed id sender void actionsheet uiactionsheet actionsheet diddismisswithbuttonindex nsinteger buttonindex 從plis...

ios學習筆記

1.nsselectorfromstring nsstring string 從乙個字串構建乙個selector.2.字串 cocoa處理字串的類nsstring和它的子類nsmutablestring。id stringwithformat nsstring format,指可以接受以逗號分開的多...