1
00:00:07,800 --> 00:00:12,900
Hey everybody this is Caleb with slopes dot com and in this video we're going to fix that dismissal

2
00:00:12,900 --> 00:00:18,750
error that we had in the last video where we dismissed finished goals Visi but instead of dismissing

3
00:00:18,750 --> 00:00:24,030
two goals Visi it dismissed back on top of create goal VC which we did not want.

4
00:00:24,120 --> 00:00:29,510
Once we leave that view controller we want to leave it forever and dismiss back down to goals.

5
00:00:29,510 --> 00:00:34,860
VC So in this video we're going to fix that by modifying our you view controller extension.

6
00:00:35,040 --> 00:00:38,620
So go ahead and pull open your X code project and go there now.

7
00:00:38,700 --> 00:00:44,970
Do you view controller XTi And what we're going to do is we're going to create a modification of present

8
00:00:44,970 --> 00:00:45,810
detail.

9
00:00:45,960 --> 00:00:53,640
Now the issue is that we are presenting create goals Visi like so let me show you in the simulator here

10
00:00:54,780 --> 00:01:01,120
we are presenting it just like so we're typing something and now we're calling present detail again.

11
00:01:01,320 --> 00:01:05,020
So we are presenting this view controller on top of this one.

12
00:01:05,240 --> 00:01:06,480
OK that's fine.

13
00:01:06,480 --> 00:01:13,240
But the issue is that when we give it some points like one and we press create goal it's dismissing.

14
00:01:13,260 --> 00:01:19,830
But since this is the one that presented it it is dismissing back to this one and not the view controller

15
00:01:20,070 --> 00:01:21,150
that we want.

16
00:01:21,150 --> 00:01:26,670
So we're going to write a function that's actually going to dismiss create goals Visi and then instantiate

17
00:01:26,670 --> 00:01:32,580
the new View Controller from goals AVC so that when we actually dismiss to create our goal at the very

18
00:01:32,580 --> 00:01:40,410
end like so like this when we press create goal it's actually going to dismiss all the way back down

19
00:01:40,470 --> 00:01:41,890
to the home view.

20
00:01:41,970 --> 00:01:49,250
The goals Visi so to do that go ahead and type phunk present secondary detail.

21
00:01:49,560 --> 00:01:57,270
And of course we're going to need a view controller to present of type UI view controller and we're

22
00:01:57,270 --> 00:01:58,710
going to give it some curly brackets.

23
00:01:58,710 --> 00:02:06,080
Now the thing is this is going to be the exact same transition the duration the type the subtype.

24
00:02:06,120 --> 00:02:12,050
The only thing that's going to change is that we're going to first create a.

25
00:02:12,480 --> 00:02:18,090
The only thing that changes is that we are first going to create a reference to the presented view controller

26
00:02:18,510 --> 00:02:24,140
meaning we're going to create a reference to whatever view controller is currently presenting.

27
00:02:24,330 --> 00:02:25,950
We're going to dismiss that one.

28
00:02:25,950 --> 00:02:30,630
And then upon the completion we're going to add the animation to the new one so we're basically going

29
00:02:30,630 --> 00:02:33,570
to remove and animate and present the new one.

30
00:02:33,610 --> 00:02:35,780
All at the same time with this function.

31
00:02:35,790 --> 00:02:37,640
So go ahead and paste this in.

32
00:02:37,740 --> 00:02:42,990
And now we're going to do is we're going to basically create a constant that's going to hold our presented

33
00:02:42,990 --> 00:02:44,780
view controller.

34
00:02:44,880 --> 00:02:49,680
If you go into any view controller you can go ahead and find which one presented it by calling presented

35
00:02:49,680 --> 00:02:53,820
a view controller so let's use guard lead to create this by typing.

36
00:02:53,820 --> 00:02:57,970
Guard let presented view controller.

37
00:02:58,500 --> 00:03:02,410
And we're going to set that to be equal to the presented view controller.

38
00:03:02,400 --> 00:03:06,220
Now this is the view controller that is presented by this view controller.

39
00:03:06,330 --> 00:03:06,990
OK.

40
00:03:07,380 --> 00:03:13,880
So let's say that we call present secondary detail on Create Goals visi.

41
00:03:14,290 --> 00:03:19,990
We're going to go ahead and this is basically just a reference that references that controller.

42
00:03:20,100 --> 00:03:20,810
OK.

43
00:03:21,180 --> 00:03:24,780
Now if that doesn't work of course we're going to need to return.

44
00:03:24,870 --> 00:03:30,270
But assuming that it does work assuming we have a presented view controller we're going to go ahead

45
00:03:30,300 --> 00:03:36,570
and call presented view controller dismiss and we're going to go ahead and call animated false.

46
00:03:36,630 --> 00:03:39,370
Right because we're overriding this animation now.

47
00:03:39,390 --> 00:03:41,430
The completion is where things matter.

48
00:03:41,430 --> 00:03:47,340
Once it has properly dismissed meaning once it's gone and there's no animation we're going to go ahead

49
00:03:47,340 --> 00:03:54,150
and call self view that window layer just like we did earlier and we're going to add our transition.

50
00:03:54,300 --> 00:03:54,890
OK.

51
00:03:55,050 --> 00:03:57,120
Which our transition is the same as before.

52
00:03:57,150 --> 00:04:00,000
We're presenting it from the left to the right.

53
00:04:00,000 --> 00:04:02,300
So it's past that in transition.

54
00:04:02,550 --> 00:04:05,770
And the key is still KCA transition.

55
00:04:06,090 --> 00:04:06,930
That's great.

56
00:04:07,170 --> 00:04:10,530
But then what we're going to do is we're going to present the view controller we've passed in.

57
00:04:10,530 --> 00:04:15,330
So first we're going to dismiss it then we're going to add in the new transition and present the new

58
00:04:15,330 --> 00:04:15,920
one.

59
00:04:15,930 --> 00:04:23,220
So basically at the same time we are setting up goals Visi to actually present the new View Controller.

60
00:04:23,220 --> 00:04:31,290
So go ahead and call self at present and we're going to call you controller to present a controller

61
00:04:31,350 --> 00:04:35,960
to present animated is false because remember we're overwriting the animation.

62
00:04:36,120 --> 00:04:38,790
And at this point the completion doesn't matter.

63
00:04:38,790 --> 00:04:44,030
So we need to call present secondary detail we need to think where we need to call that from.

64
00:04:44,340 --> 00:04:52,270
We are first presenting create goals we see then from Create Goals VC we want to dismiss to the goals

65
00:04:52,290 --> 00:04:56,550
Visi while also simultaneously animating a new view controller on top.

66
00:04:56,580 --> 00:05:04,660
So now go into Create Goals VC and instead of saying that create goals VC is doing the presenting.

67
00:05:04,800 --> 00:05:06,150
Get rid of this altogether.

68
00:05:06,300 --> 00:05:11,240
We're not going to presented from goals Fisi we're going to instead go ahead and get the presenting

69
00:05:11,390 --> 00:05:17,250
view controller meaning the view controller that's presenting this one which is goals VC the base VC

70
00:05:17,300 --> 00:05:23,420
we want and we're going to call present secondary detail from the presenting View Controller.

71
00:05:23,690 --> 00:05:28,320
So to do that go ahead and type finish goal.

72
00:05:29,270 --> 00:05:31,130
So to do that go ahead and type finish goal.

73
00:05:31,130 --> 00:05:37,610
VC OK so now we are saying goals VC dismissed this view controller and then present the new one at the

74
00:05:37,610 --> 00:05:38,750
same time.

75
00:05:38,780 --> 00:05:40,040
Let's go ahead and BuildOn run.

76
00:05:40,070 --> 00:05:41,360
Let's go check to see if that works.

77
00:05:41,360 --> 00:05:51,040
And this should properly fix our dismissal error all right cool so press add goal eat salad and let's

78
00:05:51,040 --> 00:05:57,680
make it long term press next and so you probably noticed at the same time it dismissed and animated.

79
00:05:57,690 --> 00:05:59,110
K that's cool.

80
00:05:59,120 --> 00:06:00,790
Now press 2 maybe.

81
00:06:00,950 --> 00:06:06,240
And when you press create goal watch what happens it properly dismisses to our goals.

82
00:06:06,240 --> 00:06:07,740
VC that's what we want.

83
00:06:07,820 --> 00:06:10,610
And it says it successfully save data double cool.

84
00:06:10,610 --> 00:06:12,020
So that's still working.

85
00:06:12,080 --> 00:06:14,160
Our dismissal now works perfectly.

86
00:06:14,340 --> 00:06:15,980
And awesome guys this is great.

87
00:06:15,980 --> 00:06:19,010
So I just wanted to fix that little air before we moved on.

88
00:06:19,190 --> 00:06:22,850
Let's go ahead and let's fetch our data from core data in the next video.

89
00:06:22,910 --> 00:06:28,040
Let's save it and let's fill an array with goals so that we can actually set up our table view here

90
00:06:28,040 --> 00:06:29,950
with all kinds of cool stuff.

91
00:06:29,990 --> 00:06:30,980
See in the next video.
