1

我想在 iOS 上一一显示多条消息,但问题是显示 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 并在单击按钮时更改它的消息......也许也会增加它的标签

尝试覆盖

-(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

You need one property for each alert view you want to show. In the delegate function check which one finished and start the next one:

@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 回答