Hey everybody this is Caleb with Dev soapstar calm and in this video we're going to fix that dismissal
error that we had in the last video where we dismissed finished goals Visi but instead of dismissing
two goals Visi it dismissed back on top of create goal VC which we did not want.
Once we leave that controller we want to leave it forever and dismiss back down to goals.
VC So in this video we're going to fix that by modifying or you view controller extension so go ahead
and pull open your X code project and go there now.
Do you view controller XTi And what we're going to do is we're going to create a modification of present
detail now.
The issue is that we are presenting create goals VC like so let me show you in the simulator here we
are presenting it just like so we're typing something and now we're calling present detail again.
So we are presenting this view controller on top of this one.
OK that's fine.
But the issue is that when we give it some points like one and we press create goal it's dismissing.
But since this is the one that presented it it is dismissing back to this one and not the view controller
that we want.
So we're going to write a function that's actually going to dismiss create goals Visi and then instantiate
the new View Controller from goals AVC so that when we actually dismiss to create our goal at the very
end like so like this when we press create goal it's actually going to dismiss all the way back down
to the home view.
The goals VC so to do that go ahead and type phunk present secondary detail.
And of course we're going to need a view controller to present of type UI view controller and we're
going to give it some curly brackets.
Now the thing is this is going to be the exact same transition the duration the type the subtype.
The only thing that's going to change is that we're going to first create a.
The only thing that changes is that we are first going to create a reference to the presented view controller
meaning we're going to create a reference to whatever view controller is currently presenting.
We're going to dismiss that one and then upon the completion we're going to add the animation to the
new one.
So we're basically going to remove and animate and present the new one.
All at the same time with this function.
So go ahead and paste this in.
And now we're going to do is we're going to basically create a constant that's going to hold our presented
view controller.
If you go into any view controller you can go ahead and find which one presented it by calling presented
a view controller so let's use guard lead to create this by typing.
Guard let presented view controller.
And we're going to set that to be equal to the presented view controller.
Now this is the view controller that is presented by this view controller.
OK.
So let's say that we call present secondary detail on Create Goals.
VC we are going to go ahead and this is basically just a reference that references that controller.
OK.
Now if that doesn't work of course we're going to need to return.
But assuming that it does work assuming we have a presented view controller we're going to go ahead
and call presented view controller dismiss and we're going to go ahead and call animated false.
Right because we're overriding the animation now now the completion is where things matter.
Once it has properly dismissed meaning once it's gone and there's no animation we're going to go ahead
and call self view window layer just like we did earlier and we're going to add our transition.
OK.
Which our transition is the same as before.
We're presenting it from the left to the right.
So let's pass that in transition.
And the key is still KCA transition.
That's great.
But then what we're going to do is we're going to present the view controller we've passed in.
So first we're going to dismiss it then we're going to add in the new transition and present the new
one.
So basically at the same time we are setting up goals Visi to actually present the new View Controller.
So go ahead and call self at present and we're going to call you controller to present your controller
to present.
Animated is false because remember we're overwriting the animation.
And at this point the completion doesn't matter.
So we need to call present secondary detail we need to think where we need to call that from.
We are first presenting create goals we see then from Create Goals VC we want to dismiss to the goals
Visi while also simultaneously animating a new view controller on top.
So now go into Create Goals Visi and instead of saying that create goals VC is doing the presenting.
Get rid of this altogether.
We're not presented from goals.
VC we're going to instead go ahead and get the presenting the controller meaning the view controller
that's presenting this one which is goals.
The base VC we want and we're going to call present secondary detail from the presenting View Controller.
So to do that go ahead and type finish goal.
So to do that go ahead and type finish go.
VC.
So now we are saying goals VC dismiss this view controller and then present the new one at the same
time.
Let's go ahead and build and run.
Let's go check to see if that works.
And this should properly fix our dismissal error.
All right cool so press add goal eat salad and let's make it long term press next and so you probably
noticed at the same time it dismissed and animated.
K that's cool.
Now press 2 maybe.
And when you press create goal watch what happens it properly dismisses to our goals.
VC that's what we want.
And it says it successfully save data double cool.
So that's still working.
Our dismissal now works perfectly.
And awesome guys this is great.
So I just wanted to fix that little air before we moved on.
Let's go ahead and let's fetch our data from core data in the next video.
Let's save it and let's fill an array with goals so that we can actually set up our table view here
with all kinds of cool stuff I'll see in the next video.