On this tutorial, the author has these declarations:
on .h
UIViewController *presentingViewController;
...
@property (retain) UIViewController *presentingViewController;
on .m
@synthesize presentingViewController;
at some point in code, inside a block, he does:
self.presentingViewController = viewController;
and then
[presentingViewController dismissModalViewControllerAnimated:NO];
I find this very strange. If is is assigning the viewController to self.presentingViewController, should’t it be calling
[self.presentingViewController dismissModalViewControllerAnimated:NO];
?
I have changed his code to
.h
@property (retain) UIViewController *presentingViewController;
.m
@synthesize presentingViewController = _presentingViewController;
and what I do is:
self.presentingViewController = viewController;
and then
[self.presentingViewController dismissModalViewControllerAnimated:NO];
the problem is that, self.presentingViewController is nil at this line, even being declared as retain and never being released.
any clues?
thanks
Did you remove the instance variable
UIViewController *presentingViewControllerwhen you added the instance variableUIViewController *_presentingViewController? If not i would put money on you accidentally using the wrong one at some point.Stepping through.. originally you had an instance variable
And from the property syntactic sugar you have the two accessor methods for setting and getting the variable
at some point in code, inside a block, he does:
and then
which is fine, but you think it should be
which is also fine but somewhat unnecessary.
Then you added a new instance variable:-
so now you have
But almost certainly, somewhere you are confusing the two ivars (or you aren’t aware you have two ivars) presentingViewController / _presentingViewController and still have a reference to the presentingViewController ivar, leading you to think your property is nil.