I have no idea what MessageDlg()
is, but you can certainly subclass UIAlertView
and handle the dialog response, based on which button is pressed, e.g.:
Set up the UIAlertView
subclass header:
//
// ARReachabilityAlertView.h
//
#import <UIKit/UIKit.h>
@interface ARReachabilityAlertView : UIAlertView <UIAlertViewDelegate> {
}
@end
Set up the UIAlertView
subclass implementation:
//
// ARReachabilityAlertView.m
//
#import "ARReachabilityAlertView.h"
@implementation ARReachabilityAlertView
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self setTitle:@"Error"];
[self setMessage:@"This application won't run without a network connection. Do you want to quit?"];
[self addButtonWithTitle:@"Quit"];
[self addButtonWithTitle:@"Continue"];
[self setDelegate:self];
}
return self;
}
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0)
exit(0); // quit application if "Quit" is pressed; otherwise, do nothing
}
- (void) drawRect:(CGRect)rect {
[super drawRect:rect];
}
- (void) dealloc {
[super dealloc];
}
@end
Note the alertView:clickedButtonAtIndex:
delegate method. This handles the conditionals you use to decide how the application proceeds. You can send an NSNotification
from here, or call a method in the application delegate, whatever you want.
In my example, this UIAlertView
is instantiated if there is no network connection, and the application is closed if the user clicks "Quit" in the alert view. Otherwise, if the user clicks "Continue" the application keeps running as usual.
Note that the implementation of the subclass requires the drawRect:
method be called. I'm not sure if this is a bug or not, since I'd expect the drawRect:
method to be called in the super-class; I filed a bug report with Apple on this one, but I haven't heard anything. Comment it out if you want to see what the effect will be — it's kind of interesting.