Question

I am using the presentViewController method to present a subview as shown below. However, I need to be able to stop the subview from loading if a valid license does not exist. I must do it from the subview.

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag
{
    NSBundle *bundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"innerID-iOS-Resources" withExtension:@"bundle"]];
    if (bundle) {
        if (!self.cameraVC) {
            self.cameraVC = [[IDCameraViewController alloc] initWithNibName:@"IDCameraViewController" bundle:bundle];
        }
        [self.cameraVC willMoveToParentViewController:self];
        [self addChildViewController:self.cameraVC];
        [self.view addSubview:self.cameraVC.view];
        [self.cameraVC didMoveToParentViewController:self];
    }
}

There is a callback method that calls the following closeCameraView method when done. I do not want to use another callback for when license does not exist.

- (void)closeCameraView
{
    [self.cameraVC willMoveToParentViewController:nil];
    [self.cameraVC.view removeFromSuperview];
    [self.cameraVC removeFromParentViewController];
    [self showControls];
}

The viewDidLoad is the first method that gets executed when the subview is presented.

I want to check for a valid license and return to the calling view if one does not exist.

- (void)viewDidLoad
{
    [super viewDidLoad];

    if ([self isLicenseValid]) {
        self.cameraSettings = [IDCameraSettings cameraSettings];
    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"License Activation"
                                   message:@"A valid license must be activated for this product."
                                  delegate:self
                         cancelButtonTitle:@"OK"
                         otherButtonTitles:nil];
        [alert show];

        //Do not load view
    }
}

I've tried the following two approaches to no avail and am having difficulty finding similar questions/answers on the Internet.

[self.view removeFromSuperview];
[self.parentViewController dismissViewControllerAnimated:YES completion:Nil];

Any ideas? Please.

Thank you, Lucy

Was it helpful?

Solution

By the time viewDidLoad is called, the view is, as the method name suggests, already loaded. So you can't stop the view from loading at that point.

From the little bit of code you show, it looks like you could just call your isLicenseValid method on your view controller before you try to display it, since it's the act of trying to display it that will cause it to load its views.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top