1. 程式人生 > >iOS--UIAlertView的使用方法詳細

iOS--UIAlertView的使用方法詳細

// UIAlertView的常用方法

 // 標準樣式

 UIAlertView *oneAlertView = [[UIAlertView alloc] initWithTitle:@"標題"message:@"提示內容" delegate:self cancelButtonTitle:@"關閉"otherButtonTitles:@"OK", nil];

    [oneAlertView show]; // 顯示出來

    [oneAlertView release], oneAlertView = nil// 釋放記憶體

    oneAlertView.alertViewStyle

 = UIAlertViewStyleDefault; // 設定oneAlerView的樣式

//    UIAlertViewStyleDefault 只彈資訊和按鈕

//    UIAlertViewStyleSecureTextInput 有一個textfield加密框

//    UIAlertViewStylePlainTextInput 有一個不加密的textfield

//    UIAlertViewStyleLoginAndPasswordInput 有兩個textfieldLoginpassword

IOS--UIAlertView的使用方法詳細

// 按鈕橫排顯示

 UIAlertView *twoAlertView = [[

UIAlertView alloc] initWithTitle:@"標題"message:@"提示內容" delegate:self cancelButtonTitle:@"關閉" otherButtonTitles:@"按鈕1", @"按鈕2", @"按鈕2", nil];

    [twoAlertView show]; // 顯示出來

    [twoAlertView release], twoAlertView = nil; // 釋放記憶體

IOS--UIAlertView的使用方法詳細

// 添加了多個按鈕,那麼要怎麼判斷我們按下的是哪個按鈕呢?

// 需要在.h檔案中實現UIAlertViewDelegate代理,然後在.m檔案中重寫下面的方法

#pragma mark - 實現UIAlertView的代理方法判斷按了哪個按鈕

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

 // 獲取您按下的是哪個按鈕

    NSString* msg = [[NSString allocinitWithFormat:@"您按下的第%d個按鈕!",buttonIndex];

    NSLog(@"%@", msg);

    [msg release], msg = nil;

 // 點選取消按鈕1”按鈕2”按鈕3”的索引buttonIndex分別是0123

}

// 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];

IOS--UIAlertView的使用方法詳細

// 還有很多方法,想深入瞭解的可以檢視api自己慢慢試試。這些基本夠用了。。。