I have recently begun my studies on iOS development so forgive me if I am asking something too obvious.
When my application’s view loads it checks the configurations for some keys and if there’s no value for these keys the application should display an alert and quit.
First of all, I have implemented the UIAlertViewDelegate:
@interface FirstViewController : UIViewController <UIAlertViewDelegate> {
...
And then checked for the settings:
- (void)viewDidLoad {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *url = [defaults stringForKey:@"url"];
NSString *apiKey = [defaults stringForKey:@"api-key"];
if([url length] < 1 || [apiKey length] < 1){
UIAlertView *dialog = [[[UIAlertView alloc]
initWithTitle:@"Not properly configured"
message:@"This application was not properly configured. Please configure the application on your iPhone settings."
delegate:self
cancelButtonTitle:@"Close"
otherButtonTitles:nil]
autorelease];
[dialog setTag:1];
[dialog show];
}
[url release];
[apiKey release];
[super viewDidLoad];
}
I understand that the method alertView didDismissWithButtomIndex should be called after the alertView’s dismiss but for some reason this method is never called in my code.
- (void)alertView:(UIAlertView *)alertView didDismissWithButtomIndex:(NSInteger)buttomIndex {
if([alertView tag] == 1){
exit(0);
}
}
Any ideas on why this is happening?
didDismissWithButtonIndex is misspelled, you snuck an ‘m’ in there instead of ’n’.