AutoLayout: removeFromSuperview / removeConstraints throws exception and crashes hard

后端 未结 13 2248
谎友^
谎友^ 2020-11-27 11:05

We use auto layout constraints selectively, primarily to position labels in relation to editable field elements (UITextView, UITextField, typically). However, since impleme

13条回答
  •  天命终不由人
    2020-11-27 11:24

    I got this problem with MZFormSheetController pod: https://github.com/m1entus/MZFormSheetController/issues/78

    This code crashes:

    [formSheetController.view addSubview:self.sharePanel];
    // ...
    [self.sharePanel removeFromSuperview]; // <-- CRASHES HERE
    

    My solution is very strange but it works:

    [self.sharePanel removeFromSuperview]; // <-- This line helps to avoid crash
    [formSheetController.view addSubview:self.sharePanel];
    // ...
    [self.sharePanel removeFromSuperview];
    

    And here is sharePanel property declaration:

    @property (weak, nonatomic) IBOutlet UIView *sharePanel;
    

提交回复
热议问题