UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"タイトル" message:@"アラートメッセージ" delegate:self cancelButtonTitle:@"あか" otherButtonTitles:@"あお",@"きいろ",@"みどり",nil]; [alert show]; [alert release];
アラートビューを表示する。alloc の後、init だけして処理を個別にするのも可。
ちなみに、otherButtonTitles は s で複数形なので配列を受け取るから最後にnilが必要。
-(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { switch (buttonIndex) { case 0: self.view.backgroundColor = [UIColor redColor]; break; case 1: self.view.backgroundColor = [UIColor blueColor]; break; case 2: self.view.backgroundColor = [UIColor yellowColor]; break; case 3: self.view.backgroundColor = [UIColor greenColor]; break; }
アラートビューのボタンが押された時の処理。ボタンに追加した順にインデックスされている? cancelButtonIndex プロパティでキャンセルボタンの順番は変更できる。
0 件のコメント:
コメントを投稿