// 生成例 UIAlertView *alert = [[UIAlertView alloc] init]; // 生成と同時に各種設定も完了させる例 UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"タイトル" message: @"メッセージ" delegate:nil cancelButtonTitle:nil otherButtonTitles: @"OK" , nil]; |
delegate
// デリゲートを設定 例)alert.delegate = self;
cancelButtonIndex
// 1つめのボタンをキャンセルボタンに設定する 例)alert.cancelButtonIndex = 0;
numberOfButtons
// アラートビュー内のボタン数を取得 例)int count = alert.numberOfButtons;
firstOtherButtonIndex
// OtherButtonの位置を取得 例)int no = alert.firstOtherButtonIndex; ※キャンセルボタンが存在していると値は「1」、無いと値は「0」となる。
title
例)alert.title = @"たいとる";
message
例)alert.message = @"めっせーじです";
visible
// アラートビューが表示されているかを確認 例)BOOL showAlert = alert.visible;
alertViewStyle
スタイル | |
UIAlertViewStyleDefault | 基本(通常のアラートビュー) |
UIAlertViewStyleLoginAndPasswordInput | ログイン、パスワード入力用のテキストフィールドが表示される |
UIAlertViewStylePlainTextInput | アラートビューにテキストフィールドが表示される |
UIAlertViewStyleSecureTextInput | テキストフィールド内に入力した値が隠れる(パスワード入力時と同様) |
initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:
- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)...
例)alert = [[UIAlertView alloc] initWithTitle:@"警告" message:@"よろしいですか?" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil
addButtonWithTitle:
- (NSInteger)addButtonWithTitle:(NSString *)title
例)[alert addButtonWithTitle:@"たいとる"];
buttonTitleAtIndex:
- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex
例)NSString *title = [alert buttonTitleAtIndex:0];
dismissWithClickedButtonIndex:animated:
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
例)[alert dismissWithClickedButtonIndex:0 animated:YES];
show
- (void)show
例)[alert show];
textFieldAtIndex:
- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex
例)NSString *title = [alert textFieldAtIndex:0];