iOS--UIAlertView的使用方法詳細
// UIAlertView的常用方法
// 標準樣式
UIAlertView *oneAlertView = [[UIAlertView alloc] initWithTitle:@"標題"message:@"提示內容" delegate:self cancelButtonTitle:@"關閉"otherButtonTitles:@"OK", nil];
[oneAlertView show]; // 顯示出來
[oneAlertView release], oneAlertView = nil; // 釋放記憶體
oneAlertView.alertViewStyle
// UIAlertViewStyleDefault 只彈資訊和按鈕
// UIAlertViewStyleSecureTextInput 有一個textfield加密框
// UIAlertViewStylePlainTextInput 有一個不加密的textfield
// UIAlertViewStyleLoginAndPasswordInput 有兩個textfield,Login和password
// 按鈕橫排顯示
UIAlertView *twoAlertView = [[
[twoAlertView show]; // 顯示出來
[twoAlertView release], twoAlertView = nil; // 釋放記憶體
// 添加了多個按鈕,那麼要怎麼判斷我們按下的是哪個按鈕呢?
// 需要在.h檔案中實現UIAlertViewDelegate代理,然後在.m檔案中重寫下面的方法
#pragma mark - 實現UIAlertView的代理方法判斷按了哪個按鈕
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
// 獲取您按下的是哪個按鈕
NSString* msg = [[NSString alloc] initWithFormat:@"您按下的第%d個按鈕!",buttonIndex];
NSLog(@"%@", msg);
[msg release], msg = nil;
// 點選“取消”,“按鈕1”,“按鈕2”,“按鈕3”的索引buttonIndex分別是0,1,2,3
}
// 給UIAlertView新增其他
UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"請等待"
message:nil
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
[alert show];
UIActivityIndicatorView *activeView = [[UIActivityIndicatorViewalloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activeView.center = CGPointMake(alert.bounds.size.width/2.0f, alert.bounds.size.height-40.0f);
[activeView startAnimating];
[alert addSubview:activeView];
[activeView release];
[alert release];
// 還有很多方法,想深入瞭解的可以檢視api自己慢慢試試。這些基本夠用了。。。