UIAlertView警報 IOS開發

2021-08-26 17:29:55 字數 823 閱讀 4870

uialertview* myalert = [[uialertview alloc] initwithtitle:@"sorry" message:@"1234567890" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil, nil]; myalert.delegate = self; [myalert show]; //[myalert release];//如果未在下面的委託中release的話記得要在這裡release,否則記憶體洩漏了 這裡設定delegate有啥用出,加入我們僅僅是只要顯示乙個彈窗警告,而不採取其他動作我們可以安全用如下**解決:

[[[[uialertview alloc] initwithtitle:@"sorry" message:@"1234567890" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil, nil] autorelease] show];

設定委託有啥作用呢?我們可以實現uialertview的乙個委託方法,讓後可以在這個方法裡處理按下按鈕後的動作,根據使用者按下的哪個按鈕來決定進行射門樣的操作,比如按下ok按鈕與按下cancel按鈕的後要進行的操作必然有可能不同:

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

看到否?我們可以通過buttonindex來判斷使用者按下了哪個按鈕,然後來進行相應處理,同時我們還可以在這裡面release,因為我們在上面的**中可能不確定需要在**release,所以在按下按鈕後release是不是最安全的呢?

UIAlertView自動消失

話說,在寫程式的過程中用到很多提示的資訊,於是非常自然地就要使用uialertview控制項。但是這些提示的資訊有時候只需提示就行,不用操作,那麼此時就要這個提示框自動消失就ok了。uialertview彈出後2s讓其自動消失,兩種方法 1 結合nstimer uialertview baseale...

ios學習筆記 UIAlertView

uialertview view uialertview alloc initwithtitle 標題 message 內容 delegate nil cancelbuttontitle 取消 otherbuttontitles 確定 nil view.alertviewstyle uialertv...

IOS開發 UIAlertView設定文字左對齊

今天碰到乙個設定uialertview中間message的文字左對齊的問題,因為iphonesdk預設是居中對齊的,而且沒有提供方法設定文字對齊介面,解決這個問題的思路很簡單,就是在delegate void willpresentalertview uialertview alertview 獲取...