3

I've been looking all over the internet for a solution to this problem, yet to find one that I can understand. So here it goes. I have my iOS application, on which on the first launch of the application, will display a UIAlertView. I want one of the buttons to send the user to a new viewController to view some essential information.

I have gotten my UIAlertView configured properly, here's 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's what I want users to reach when they tap the first button. Any ideas on how to do this? I have ARC disabled, other 'solutions' i've come across keep giving me errors.

Thanks all, would appreciate some guidance here.

iPwnTech
  • 545
  • 2
  • 5
  • 20
  • First of all, `exit(0)`: never! Tip: http://stackoverflow.com/questions/14335848/exit-application-when-click-button-ios Then, to instance a new UIViewController, Apple Doc should be useful. – Larme Jan 21 '13 at 11:51
  • I've been a bad boy, I'll change that. Could you help me tho? – iPwnTech Jan 21 '13 at 11:53
  • To show an alert view you have to first launch a rootView.. – Anusha Kottiyal Jan 21 '13 at 11:54
  • I have a UIAlertView, read my question – iPwnTech Jan 21 '13 at 11:55
  • what i have understand is you have screen A and B . You have alert view on screen view .And if you click one of the button then it should go in B .Right ? – V-Xtreme Jan 21 '13 at 11:58
  • Oky... i know, You already have been got answered of This Question but also [see This Answer](http://stackoverflow.com/questions/14534513/unknown-receiver-in-xcode-project/14534579#14534579) – iPatel Jan 26 '13 at 09:52

3 Answers3

0

If your current viewcontroller 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)!

drasick
  • 280
  • 4
  • 14
0
- (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 has given sufficient answer but if you need to use model view controller refer above.

V-Xtreme
  • 7,230
  • 9
  • 39
  • 79
  • Receiving 'unknown receiver' and 'unknown type name', my view controller name is webviewviewcontroller, any ideas? – iPwnTech Jan 21 '13 at 12:17
  • forward declare class @class className instead on #import in the .h file and do #import in .m to avoid circular dependancies – V-Xtreme Jan 21 '13 at 12:36
0

Use:

UIViewController *yourViewController = [[UIViewController alloc] init];
[self.navigationController presentModalViewController:myViewController animated:YES];

to push a modalViewController.(This is depriciated in iOS 6, but will work)

user1710004
  • 209
  • 1
  • 4
  • 12