why will UIViewController viewWillAppear not run after subViews are removed from superView

133 Views Asked by At

I am doing a subLayer to a UIViewController like this

- (IBAction)transactionListViewCameraBtn_Pressed:(id)sender {

    if([NWTillHelper isDebug] == 1) {
        NSLog(@"%s entered", __PRETTY_FUNCTION__);
    }

    self.capture = [[ZXCapture alloc] init];
    self.capture.camera = self.capture.back;
    self.capture.focusMode = AVCaptureFocusModeContinuousAutoFocus;

    [self.view.layer addSublayer:self.capture.layer];

    self.capture.delegate = self;

    [self applyOrientation];
}

The problem is that when I remove the subLayer I expect the original Views viewWillAppear to run but it isn't.

I am removing the subLayer like this

[self.capture.layer removeFromSuperlayer];

Is viewWillAppear not supposed to run when the original View appears again?

If not how can I ensure the code I have in viewWillAppear will run when I remove the subLayer?

1

There are 1 best solutions below

0
Francesco Deliro On BEST ANSWER

As suggested check the Apple doc for understand view life cycle. Then you can put your viewWillAppear code in a new method:

-(void)yourFunctionName {
    //your code here 
}

And call it where you need.

But, maybe, if you just need to update your layout you can check setNeedsLayout and layoutIfNeededmethods.