1

iOSで複数のメッセージを1つずつ表示したいのですが、問題はUIAlertViewの表示がブロックされないことです。アラートの終了を処理してclickedButtonAtIndex、同じアラートを内部に表示しようとしました。ここにいくつかのコードがあります:

@interface ViewController : UIViewController <UIAlertViewDelegate>
...
@property UIAlertView *alert;
...
@end

...
[alert show]; //somewhere in code, starts chain of messages
...

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    // Some changes in alert object
    [alert show];
}
4

3 に答える 3

2

UIAlertViewが1つあり、ボタンをクリックするとメッセージが変更されます...タグもインクリメントする可能性があります

オーバーライドしてみてください

-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex

それ以外のclickedButtonAtIndex

于 2012-07-21T21:59:24.683 に答える
2

アラートビューにタグを設定することを好みます。

#define ALERT_1   1
#define ALERT_2   2

...
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:...];
alert.tag = ALERT_1;
[alert show]; //somewhere in code, starts chain of messages
...

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (alertView.tag) {

        case ALERT_1: {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:...];
            alert.tag = ALERT_2;
            [alert show];
        } break;

        case ALERT_2: {
           ....
        } break;
    }

}

このように、アラートビューに変数を使用する必要はありません。

于 2012-07-21T23:57:53.437 に答える
0

表示するアラートビューごとに1つのプロパティが必要です。デリゲート関数で、どちらが終了したかを確認し、次の関数を開始します。

@interface ViewController : UIViewController <UIAlertViewDelegate>
...
@property UIAlertView *alert1;
@property UIAlertView *alert2;
@property UIAlertView *alert3;

@end

...
alert1 = [[UIAlertView alloc] initWithTitle:...];
[alert1 show]; //somewhere in code, starts chain of messages
...

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView == alert1) {
        alert2 = [[UIAlertView alloc] initWithTitle:...];
        [alert2 show];
    } else if (alertView == alert2) {
        alert3 = [[UIAlertView alloc] initWithTitle:...];
        [alert3 show];
    }

}
于 2012-07-21T21:43:27.410 に答える