Your code does not generate leaks, as you are allocating the popover once. However, you do not need to create an instance variable manually, or to set the popover property to nil, ARC will take care of this, unless you want to also deallocate the popover before your VC is deallocated.
Just make sure you are not adding the popover view multiple times to the parent view (i.e. not calling openButtonPressed
again before calling closePopup
.
.h:
@interface MainViewControoler : UIViewController
@property (nonatomic) PopupViewController *popupView;
@end
.m:
-(void)openButtonPressed
{
if (!_popupView)
{
_popupView = [[PopupViewController alloc] init];
_popupView.delegate = self;
}
[self.view addSubview:_popupView.view];
_popupView.view.frame = self.view.frame;
}
-(void)closePopup
{
[_popupView.view removeFromSuperview];
}