0

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");
        }

}
4

2 に答える 2

5

It probably isn't the same "white" as returned by [UIColor whiteColor]. If you pick the white color in IB for your view and log it, you get: UIDeviceRGBColorSpace 1 1 1 1

If you then set the color to [UIColor whiteColor], and log it again, you get: UIDeviceWhiteColorSpace 1 1

于 2012-06-08T03:30:52.163 に答える
1

述べたように、実際には [UIColor whiteColor] ではありません。ビューの読み込み時に手動で設定します。

- (void)viewDidLoad
{
    self.view.backgroundColor = [UIColor whiteColor];
}
于 2012-06-08T03:33:27.187 に答える