UIAlertView の [OK] ボタンをクリックすると、ビューの背景色を変更する必要があります。デフォルトの色は白なので、ユーザーが [OK] をクリックするたびに、たとえば白と赤の 2 つの色を交互に切り替える必要があります。 :
-(void)changeColor{
if([self.view.backgroundColor isEqual: [UIColor whiteColor]]){
self.view.backgroundColor=[UIColor redColor];
}else {
self.view.backgroundColor=[UIColor whiteColor];
}
}
問題は、最初の [OK] クリックで色が赤になるはずですが、赤にならないため、[OK] ボタンを 2 回クリックしてビューの背景色を赤にする必要があることです。最初から色を変更するために何か不足していますか?
これはalertView:didDismissWithButtonIndex
デリゲート メソッドです。
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
if (buttonIndex==0) {
//NSLog(@"It's Ok button which has been clicked");
//Do whatever you want, commonly call to another function like so:
[self changeColor];
}else
if (buttonIndex==1) {
//NSLog(@"It's Cancel button which has been clicked");
}
}