I am trying to create an alertView from the appDelegate but I cant get it to work. The alertView will act as a disclaimer when the app launches for the first time. I cant get it to work..the introViewcontroller does not appear. what am I doing wrong? ps. i use storyboards except for the intoViewController which is a nib file.my root view controller is a “fisrtViewController” here is my code: Thank you..
int a;
and in didFinishLaunchingWithOptions
if ( a == 0) {
UIAlertView *disclaimer = [[UIAlertView alloc] initWithTitle:@"Read Before use" message:@"By using this app you agree to its terms and conditions.\n\n\n\n\n\n\n\n\n\n\ntext heren\n\n\n\n\n\n\n\n\n\n\n\n\n" delegate:self cancelButtonTitle:@"No!" otherButtonTitles:@"Yes Let me In", nil];
[disclaimer show];
}
// Override point for customization after application launch.
return YES;
}
-(void) alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1) {
// FirstViewController *firstView = [[FirstViewController alloc] init];
a+=1;
// [self.viewController presentModalViewController:firstView animated:YES];
}
else if (buttonIndex == 2) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry!" message:@"You are not allowed to use this app due to the fact that you did not agree to the terms and Conditions. Please exit this app!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
if (buttonIndex ==1) {
introViewController *intro = [[introViewController alloc] initWithNibName:@"introViewController" bundle:nil];
[self.viewController presentModalViewController:intro animated:YES];
introViewController *intro = [[introViewController alloc] initWithNibName:@"introViewController" bundle:nil];
[self.viewController presentModalViewController:intro animated:YES];
}
}
ahh… Now I Understand what you are trying to do.
You problem is that
self.viewControlleris not set before you try to present a new modal ViewController. Also, I think your buttonIndex is of by one.Try instead:
Since your problem has nothing to to do with the
UIAlertView, You might want to change the title and description of your question to make it more clear, for others struggling with a similar problem.Happy coding! 🙂