Alertメッセージの出し方

iPhoneのAlert(警告ダイアログ)はUIAlertViewで出します。
モーダル型(子ウインドウが開いてそこで操作をするまで親ウインドウの操作ができない)のダイアログになります。


Alertメッセージ方法
UIAlertViewのインスタンスを作ってshowするだけです。
引数は下の例を参考にしてください。
注意点はotherButtonTitlesで最後のnilを忘れないように。

 - (void)viewDidLoad {
  [super viewDidLoad];
  UIAlertView *alertView = [[UIAlertView alloc] 
                             initWithTitle:@"ここがタイトル"
                             message:@"ここが本文"                             
                             delegate:self
                             cancelButtonTitle:@"キャンセルボタンです"
                             otherButtonTitles:@"1個目のボタン",
                                               @"2個目のボタン",                             
                                               nil];
[alertView show];
[alertView release];
}




delegate:selfと記述したので自クラスでデリゲートを実装します。

@interface testViewController : UIViewController 
/* アラートのデリゲートメソッド */
 - (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
  //ボタンを押された後に行いたいことを記述
  //buttonIndexで押されたボタンを識別できる
}