iphone程式開發 alert使用



iphone上很常見的警告視窗
如何使用呢
UIAlertView *alert=[[UIAlertView allocinitWithTitle:@"Alert!" message:@"Here is an alert message!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]   ;

[alert show];
[alert release];

要加入多個按鈕則使用"otherButtonTitles達成"
   UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"alert" message:@"Here is an alert message!" delegate:self cancelButtonTitle:@"1" otherButtonTitles:@" 2", @" 3",nil ] autorelease];

[alert show];


執行如下









按下確定後的處理函式 可以透過delegate指派來達成
多個按鍵 會回傳buttonIndex 從0開始
然後再m檔裡實作
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {     // and they clicked 1.
NSLog(@"1 clicked");
        }else if(buttonIndex==1){
NSLog(@"2 clicked");
}else if(buttonIndex==2){
NSLog(@"3 clicked");
}
}


開啟log檢視器 看看事件觸發沒




留言

這個網誌中的熱門文章

Office 2021 離線安裝封裝與KMS啟動步驟

Ollama使用心得與模型導入教學

ARC下NSMutableDictionary 無法使用retainCount