0

i need help with the following code. My aim is to show the UIViewController "Terms" (already exists in my Storyboard and I have asigned the name Terms in the Storyboard ID). If the app as already been opened and the user accepted the T&C then show the normal UIViewController.

FIRSTVIEWCONTROLLER.H

#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController

@end

@interface First : UIViewController

@end

@interface Terms: UIViewController

@end

FIRSTVIEWCONTROLLER.M

#import "FirstViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

- (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];
    }

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

As it is, I am receiving 2 errors: "Unexpected interface name 'Terms'/'First': expected expression".

Please take a look at the storyboard: https://i.stack.imgur.com/bi6aT.png

Help me please. xcode beginner.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
jmfer1
  • 13
  • 4
  • Where are you seeing the errors? Point out the exact code giving you the problem. – rmaddy May 02 '14 at 22:22
  • Your storyboard looks weird because you don't have an arrow going to the terms and you have lots of arrows going to the tab bar controller. It all seems inverted (but I don't know what its intended to do). If a beginner with XCode/storyboards start with one view controller, run it, then add another and run again, then add another and run again etc. Build it up bit by bit slowly – Gruntcakes May 02 '14 at 22:30
  • @rmaddy the error appears on `[self presentViewController:Terms animated:YES completion:nil];` and on `[self.navigationController pushViewController:First animated:YES];` Thank you. – jmfer1 May 02 '14 at 22:31
  • You are trying to pass the names of the classes instead of creating instances of the view controllers. – rmaddy May 02 '14 at 22:35

1 Answers1

0

First off, remove these lines from your .h since they're unnecessary:

@interface First : UIViewController

@end

@interface Terms: UIViewController

@end

Secondly, your Storyboard doesn't look quite right... From the FirstViewController, you need to create segues between the view and both potential subsequent view controllers, i.e. "First" and "Terms", using the method I've specified here: https://stackoverflow.com/a/20690072/2274694; then label those segues with identifiers.

That way, if you want to segue to the pertinent view controller depending on whether or not the terms have already been accepted, you could perform the segue using the relevant identifier, ex:

if (!isAccepted) {
    [self performSegueWithIdentifier:@"firstSegue" sender:self];
} else {
    [self performSegueWithIdentifier:@"termsSegue" sender:self];
}
Community
  • 1
  • 1
Lyndsey Scott
  • 37,080
  • 10
  • 92
  • 128
  • Where will the "termsSegue" start? I mean from which action? – jmfer1 May 02 '14 at 22:56
  • Don't connect it to a specific action within the storyboard... Just create a general segue. I explain how in this answer: http://stackoverflow.com/a/20690072/2274694 . That way, the segue will happen where you've specified in your viewDidLoad. – Lyndsey Scott May 02 '14 at 23:03