Reputation: 1564
I want to show multiple messages on iOS one by one, but the problem is that showing UIAlertView is non-blocking. I tried to handle alert closing with clickedButtonAtIndex
and show same alert inside. Here is some code:
@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];
}
Upvotes: 1
Views: 1206
Reputation: 4819
I prefer to set tags on the alert views:
#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;
}
}
This way you don't have to use variables for the alert views.
Upvotes: 2
Reputation: 4787
I would have one UIAlertView and change its message on button click... Maybe increment its tag as well
try overriding
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
instead of clickedButtonAtIndex
Upvotes: 2
Reputation: 539775
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];
}
}
Upvotes: 0