0

I would like some help to review my code. My intention is to display a view with T&C when the app is first opened.

I am currently using the following code under the FirstViewController, as suggested here:

- (void)viewDidLoad: (BOOL)animated
{
    [super viewDidLoad];

    NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults];

    BOOL isAccepted = [standardUserDefaults boolForKey:@"iHaveAcceptedTheTerms"];

    if (!isAccepted) {
        [self presentViewController:@"Terms" animated:YES completion:nil];
    } else {
        [self.navigationController pushViewController:@"First" animated:YES];
    }

The reason why I used @"Terms" and @"First" is because otherwise it gives me error and also because I saw it suggested on a Youtube video, I am wrong?

The other method I also tryed was the one suggested on the Youtube Video:

- (void)viewDidLoad: (BOOL)animated
{
    [super viewDidLoad];
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FirstLaunch"])
    {}
    else {
        // Place code here


        UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
        UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"Terms"];
        [vc setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];


        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"FirstLaunch"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }

But neither work. Can you kindly share your thoughts and help me?

Thanks :)

Community
  • 1
  • 1
jmfer1
  • 13
  • 4

1 Answers1

1

In your first code, lines:

//...
[self presentViewController:@"Terms" animated:YES completion:nil];
//...
[self.navigationController pushViewController:@"First" animated:YES];
//...

Are passing NSStrings objects (@"Terms" and @"First") instead of UIViewControllers. Those parameter must be instances of UIViewController class.

In your second code, you are creating an instance of the UIViewcontroller (vc), but you are not presenting the view controller. In your second code you can add:

    [self presentViewController:vc animated:YES completion:nil];

After setting the transition style.

LuisEspinoza
  • 8,508
  • 6
  • 35
  • 57
  • In the first one, I had to declare both UIViewControllers ("Terms" and "First") as follows: `@interface First : UIViewController @end @interface Terms: UIViewController @end` Then, on the .m the following error appears "Unexpected interface name 'Terms'/'First': expected expression. Help? – jmfer1 May 02 '14 at 21:31