So I'm using a custom presentation controller which requires me to specify a transitioningDelegate on the view controller before presenting it like this:
vcToPresent.modalPresentationStyle = UIModalPresentationCustom;
vcToPresent.transitioningDelegate = transitionDelegate;
Now I want to enforce a particular view controller to always use my custom presentation controller. Unfortunately I cannot just override the presentationController getter and return my own custom class; I have to make a transitioning delegate and an additional animator (and my custom presentation controller can animate alongside it). To have a view controller use my own presentation controller I have to do this:
-(void)presentCustomVC
{
MyViewController *vcToPresent = [MyViewController makeViewController];
MyTransitioningDelegate *transitionDelegate = [[MyTransitioningDelegate alloc]init];
vcToPresent.modalPresentationStyle = UIModalPresentationCustom;
vcToPresent.transitioningDelegate = transitionDelegate;
[self presentViewController:vcToPresent animated:YES completion:nil];
}
So I have to copy this transitioningDelegate set up code in every view controller that presents MyViewController. I can make the API look a little better by creating a factory method in MyViewController like this:
+(MyViewController*)makeViewController
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
MyViewController *theVC = [storyboard instantiateInitialViewController];
MyTransitioningDelegate *transDelegate = [[MyTransitioningDelegate alloc]init];
theVC.modalPresentationStyle = UIModalPresentationCustom;
theVC.transitioningDelegate = transDelegate;
return theVC;
}
The problem with that is the transitioningDelegate gets deallocated right away (before the view controller can be presented). The transitioningDelegate property on UIViewController is weak for some reason.
Shouldn't the transitioningDelegate property be declared strong? My custom transitioningDelegate has no strong reference to the presented view controller? If I add a redundant property to MyViewController like this:
@property (nonatomic,strong) MyTransitioningDelegate *strongTransDelegate;
And then do this:
theVC.modalPresentationStyle = UIModalPresentationCustom;
theVC.transitioningDelegate = transDelegate;
theVC.strongTransDelegate = transitionDelegate;
All seems to work well. When the view controller is dismissed the transitioning delegate is deallocated. However I'm assuming the transitioningDelegate property on UIViewController was declared as weak for a reason? I don't want to accidentally create a retain cycle in some unforeseen circumstance. Documentation makes no mention on who should be the "owner" of the transitioning delegate?