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