質問

I want to make a "terms and conditions" screen that pops up the very first time that app is opened. On this view I would add a button that says "agree," and upon clicking it the code would execute:

[self dismissViewControllerAnimated:YES completion:nil];

...and would go to the first view of the app.

I am currently using a Tab Bar Controller that has 4 ViewControllers. So basically, I just need to have some method in viewWillAppear on my first ViewController that checks for an NSUserDefault key:value. The first time the app opens, it will be zero. After they click agree, I'll set it to 1 and the bit of code would never execute again.

Can you please offer some code to accomplish the task of routing the view from the firstViewController's view to this alternate view controller upon loading the app?

Thanks!

役に立ちましたか?

解決

In the viewWillAppear method in your FirstViewController, check NSUserDefaults then present your TermsViewController. After user click agree in TermsViewController, set NSUserDefaults then call

[self.presentingViewController dismissModalViewControllerAnimated:YES] 

他のヒント

The use of the popover window can get complicated. Try something like the following if you have little experience with Objective-C.

- (void)viewDidLoad {

    if ([termsvalue == 0]) {
        NSString *msg = [NSString stringWithFormat:@"Do you agree with the terms of use?"];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"- Confirmation -"
                                                        message:msg
                                                       delegate:self
                                              cancelButtonTitle:@"Disagree"
                                              otherButtonTitles:@"I agree", nil];
        [alert setTag:100];
        [alert show];
    }
}

- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView { // Validation
if ([alertView tag] == 100) {
    return YES;
}
}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { // Go
if ([alertView tag] == 100) {
    if (buttonIndex == 1) {
        // The user has agreed
    }
}
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top