UIAlertView button to display the viewController
I have searched all over the internet for a solution to this problem but found one that I can understand. So this is it. I have an iOS app that will display a UIAlertView when the app is first launched. I want one of the buttons to send the user to a new viewController to view important information.
I configured my UIAlertView correctly, here is the code for the ActionSheet:
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0)
{
//Code to open a new viewController???
}
if (buttonIndex == 1)
{
//User can exit the application if they do not wish to continue
exit(0); }
}
}
I have a viewController created named webViewViewController that I want users to reach when they click the first button. Any ideas how to do this? I have ARC disabled, other "solutions" I've come across keep giving me errors.
Thanks everyone, I'd love to get some guidance here.
source to share
If your current view controller is in a navigation controller:
UIViewController *myViewController = [[UIViewController alloc] init];
myViewController.title = @"My First View";
//to push the UIView.
[self.navigationController pushViewController:myViewController animated:YES];
And never use exit (0)!
source to share
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0)
{
NewViewController *controller=[[NewViewController alloc]initWithNibName:@"NewViewController" bundle:nil];
self.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
[self presentViewController:controller animated:YES completion:nil];
}
drasick gave a sufficient answer, but if you need to use a model view controller see above.
source to share