Login error after upgrading to iOS9

After updating my application to iOS9 Iam, an error message appears in my application:

: objc [344]: It is not possible to form a weak link to an instance (0x15919e00) of the LoginVC class. This object may have been released or is in the process of being released.

Below is the function in which I get this error:

-(void)dismissLogin {
self.isLoggingIn = NO;
[self stopLoginAnimation];
[self dismissViewControllerAnimated:YES completion:NO];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self.appDelegate setLoginVC:nil];
[self.view removeFromSuperview];
//[APPDEL selectTabBar];
}

The application is stuck on the login screen and does not switch to the following screens.

This error is not included in iOS8. Can anyone help me with this problem.

+4
source share
2 answers

Make sure you are not using an exempt instance.

. iOS 8, iOS 9. setDelegate .

-(void)setDelegate:(id<UICollectionViewDelegate>)delegate{
    _internalDelegate = delegate;
    [super setDelegate:self];
}

, iOS 9 -, . ,

-(void)setDelegate:(id<UICollectionViewDelegate>)delegate{
    _internalDelegate = delegate;
    if (delegate) {
        //Set delegate to self only if original delegate is not nil
        [super setDelegate:self];
    }else{
        [super setDelegate:delegate];
    }
}
+4

, , . , , , , internalDelegate , .

, , nil internalDelegate. , , - .

  • , weakSelf
@property (nonatomic, weak) LoginVC *weakSelf;
  1. weakSelf self
 - (id)init {
    if ((self = [super init])) {
        self.weakSelf = self;
    }
}
- (void)setDelegate:(id)delegate {
    _internalDelegate = delegate;
    [super setDelegate:self.weakSelf];
}
0

Source: https://habr.com/ru/post/1609469/


All Articles