简体   繁体   中英

iOS First Launch show Terms and Conditions

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: http://i.stack.imgur.com/bi6aT.png

Help me please. xcode beginner.

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, ie "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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM