I have a modal view controller that is presented in the form sheet style. It has a protocol of delegates. I implement this protocol and appoint a delegate before the presentation, but it is lost, although the property is strong. Any possible reasons are welcome. Thanks!
Here is a property declaration as strong.
@protocol SDStoreViewDelegate <NSObject> // Methods @end @interface SDStoreViewController : UIViewController @property (strong, nonatomic) id <SDStoreViewDelegate> delegate; @end
An object is created here and a set of delegates is set.
SDStoreViewController *store = [[SDStoreViewController alloc] init]; [store setDelegate:self]; NSLog(@"1 %@",store.delegate); // Returns Object as expected [self presentViewController:store animated:YES completion:^{ NSLog(@"3 %@",store.delegate); // Returns Object as expected }]; NSLog(@"4 %@",store.delegate); // Returns Object as expected
This is viewDidLoad from SDStoreViewController. He already lost a delegate
- (void)viewDidLoad { [super viewDidLoad]; NSLog(@"3 %@",_delegate);
This rejection is only because where the delegate will be called, it was not NULL.
- (void)dismiss:(id)sender { NSLog(@"5 %@",_delegate);
Update
I used weak and strong links. I also used self.delegate and _delegate to access the property. And as a point, the aMethod does not go through this, which prompted this detective work to find where it gets lost.