2017-11-03 89 views
0
刪除後的UIViewController viewWillAppear中無法運行

我做的一個子層到一個UIViewController這樣爲什麼會子視圖是由上海華

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

的問題是,當我刪除子我希望自己獨到的見解viewWillAppear中運行,但它不是。

我刪除這樣

[self.capture.layer removeFromSuperlayer]; 

的子層viewWillAppear中不應該當原始View再次出現運行?

如果不是我如何確保我在viewWillAppear中的代碼在我移除subLayer時運行?

+0

當您轉到另一個控制器並再次返回時,「viewWillAppear」調用。但你只是刪除超級層,所以它不叫。 –

+0

你可以這樣做..以2個按鈕開始並取消。開始將添加圖層,當點擊取消它將刪除圖層。 –

回答

0

建議檢查Apple doc瞭解視圖生命週期。 然後你就可以把你的viewWillAppear中的代碼在一個新的方法:

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

,並調用它,你需要的。

但是,也許如果你只是需要更新你的佈局,你可以檢查setNeedsLayoutlayoutIfNeeded方法。