1
00:00:00,530 --> 00:00:01,130
Hi there.

2
00:00:01,130 --> 00:00:01,910
Welcome back.

3
00:00:01,910 --> 00:00:06,440
In this lesson we will see some of the more advanced methods of table use.

4
00:00:06,860 --> 00:00:10,360
So I'm going to go into X scope and I'm going to start a new project.

5
00:00:10,370 --> 00:00:18,200
Call it table view methods and once they get to table view methods I'm going to actually use a table

6
00:00:18,200 --> 00:00:19,690
view controller.

7
00:00:19,700 --> 00:00:24,560
These folks I'm going to do with a little bit faster because I know you guys have done it multiple times

8
00:00:25,160 --> 00:00:30,370
so I don't need the view controller where they would need is an actual table view controller.

9
00:00:30,830 --> 00:00:35,330
And for my table viewpoint I'm also going to add a navigation controller.

10
00:00:35,750 --> 00:00:39,440
So when it start my view with a navigation controller.

11
00:00:39,680 --> 00:00:43,520
So these are the two of them you could keep your table of your controller.

12
00:00:43,580 --> 00:00:50,300
And instead of that one at a navigation controller route view controller for this or you could maintain

13
00:00:50,300 --> 00:00:55,820
a navigation controller that by default comes with a table view controller.

14
00:00:55,880 --> 00:01:01,220
The next thing I'm going to do is I'm going to add a new file a cocoa touch class that is a UI table

15
00:01:01,220 --> 00:01:02,320
view controller.

16
00:01:02,410 --> 00:01:05,510
I'm going to call it my table view controller.

17
00:01:05,510 --> 00:01:10,980
And of course my table view controller becomes the class for my table view.

18
00:01:11,180 --> 00:01:15,040
So my table view becomes my table view controller.

19
00:01:15,050 --> 00:01:21,410
Now we have only one cell in here that cell as always on when I give it an idea and when I call it to

20
00:01:21,410 --> 00:01:26,530
be cell I.D. And I want them to be a little bit taller than usual.

21
00:01:26,540 --> 00:01:30,550
So I'm going to say the raw height is actually sixty fourth.

22
00:01:30,740 --> 00:01:36,170
So I get to see a slightly taller cell on the cells all of the basic type.

23
00:01:36,170 --> 00:01:38,580
So nothing is new in there.

24
00:01:38,660 --> 00:01:43,880
The last thing they have to do is they have to make sure my navigation controller is the initiated view

25
00:01:43,880 --> 00:01:46,340
controller which is gonna be done like that.

26
00:01:46,850 --> 00:01:52,530
So now they want to do is this I want to have two sections in this table view controller and then we're

27
00:01:52,530 --> 00:01:55,760
going to move on with adding some new methods to them.

28
00:01:55,760 --> 00:02:01,010
So I will go into my table view controller and up here I'm going to go ahead and say I actually have

29
00:02:01,010 --> 00:02:02,560
two arrays.

30
00:02:02,570 --> 00:02:11,340
Let's say let's country is array which is coming to be Canada which is where I am right now.

31
00:02:11,600 --> 00:02:23,180
Let's say next form would be us next along with the Mexico next one would be India are like that and

32
00:02:23,210 --> 00:02:27,190
maybe Poland and Brazil.

33
00:02:28,740 --> 00:02:30,920
That's all the countries I can think of right now.

34
00:02:31,220 --> 00:02:37,100
And then I'm going to go ahead and say I have another one which is cities array and that's going to

35
00:02:37,100 --> 00:02:46,340
be Vancouver and from the U.S. We're going to get New York and from Mexico we're going to get Mexico

36
00:02:46,340 --> 00:02:48,680
City I'm from India.

37
00:02:48,680 --> 00:02:56,450
We're going to get New Delhi and from Portland if I'm not drawing we're going to get Warshaw and from

38
00:02:56,450 --> 00:02:57,880
Brazil we're going to get Rio.

39
00:02:58,370 --> 00:03:02,950
So we have two arrays each of them has some items in them.

40
00:03:03,170 --> 00:03:07,670
And the next thing I'm going to do is I'm going to go to the sections number of sections which we usually

41
00:03:07,670 --> 00:03:10,810
delete and we allow it to be the default value.

42
00:03:10,850 --> 00:03:13,240
This time I'm going to say actually return to.

43
00:03:14,030 --> 00:03:18,350
And then what I'm going to do is I'm going to go ahead and say the number of rows in sections.

44
00:03:18,350 --> 00:03:28,050
This rate becomes a little bit different will be if section is zero then you'll have to return countries

45
00:03:28,140 --> 00:03:41,940
array that count and else you have to say return cities array cities cities array that counts.

46
00:03:41,990 --> 00:03:46,110
So depending on the section the number of the rows is different.

47
00:03:46,130 --> 00:03:48,680
One of them is for where the countries are being shown.

48
00:03:48,680 --> 00:03:55,550
One of them is for where the cities are being shown the next thing is sell for raw index fat is going

49
00:03:55,550 --> 00:03:56,450
to be.

50
00:03:56,570 --> 00:03:59,510
Let me format everything nice and tidy.

51
00:03:59,510 --> 00:04:10,370
The sale is called sell I.D. And I'm going to go ahead and say if index part that section is zero you

52
00:04:10,370 --> 00:04:14,630
do something else you do something else.

53
00:04:14,660 --> 00:04:20,840
So if section is zero that is the country's so sell that tax table.

54
00:04:20,960 --> 00:04:26,340
That text becomes countries every index part that's wrong.

55
00:04:27,530 --> 00:04:30,290
And then I'm going to copy the same thing basic in here.

56
00:04:30,290 --> 00:04:31,510
I love countries.

57
00:04:31,580 --> 00:04:33,410
This will be cities.

58
00:04:33,770 --> 00:04:40,370
And now we should have a table view that shows us two sections one section is for the countries one

59
00:04:40,370 --> 00:04:42,330
section is for the cities.

60
00:04:42,530 --> 00:04:47,240
Now before they're on the application I'm actually going to add one more method in here.

61
00:04:47,240 --> 00:04:51,590
Let me delete everything because I want to add them manually to the method they want to add.

62
00:04:51,590 --> 00:04:57,970
Is this title for header in Section.

63
00:04:58,130 --> 00:05:10,330
So I want to see a title for header and that's going to be the return if section is zero return countries

64
00:05:10,930 --> 00:05:23,260
and areas return cities and let's run the application up until this point we haven't done anything that

65
00:05:23,260 --> 00:05:30,790
is new we probably never use the sections but we knew how to use them know that application is loaded

66
00:05:30,820 --> 00:05:35,950
we can see that they have the title in their countries and I have I can see the names of the countries

67
00:05:35,950 --> 00:05:41,090
in different cells and then I have the cities and the names of the cells in the different cities.

68
00:05:41,260 --> 00:05:45,790
Now the next thing I want to do is I want to be able to swipe and delete a cell.

69
00:05:45,790 --> 00:05:53,470
So to do that I'm going to go in here and say I need a new function called can edit raw at index spot

70
00:05:53,920 --> 00:06:01,120
so can edit through an index that essentially allows the user to either delete or insert or move a cell

71
00:06:01,120 --> 00:06:06,910
from one place to another place and you can make it dependent on the index but for instance I could

72
00:06:06,910 --> 00:06:15,140
say if index part that section is zero then return true.

73
00:06:15,370 --> 00:06:17,100
Otherwise don't return true.

74
00:06:17,200 --> 00:06:22,690
But I'm not going to do that I'm going to say let's just return true for everyone so we can you know

75
00:06:22,780 --> 00:06:26,320
edit sick cells in this entire application.

76
00:06:26,440 --> 00:06:32,020
So that's the first thing they have to do to be able to edit but the next thing that we have to do which

77
00:06:32,020 --> 00:06:38,440
is very important is we have to decide what should happen if you wanted to edit and it's telling me

78
00:06:38,650 --> 00:06:39,870
we need an override.

79
00:06:39,880 --> 00:06:44,970
Yes of course we can override why it didn't auto completed itself.

80
00:06:44,980 --> 00:06:47,080
That is a curious thing.

81
00:06:47,140 --> 00:06:51,600
Now the next thing is we have to say what happens when we do edit.

82
00:06:51,670 --> 00:07:01,180
So that's going to be comet editing style and in the comet editing is Slide 4 index and we have to decide

83
00:07:01,180 --> 00:07:06,390
what happens when you try to edit and a different editing styles.

84
00:07:06,400 --> 00:07:16,720
So I'm going to just choose one of them to say if anything aside is you eye table view cell dot editing

85
00:07:16,780 --> 00:07:21,130
style dot and enhancement a search for delete.

86
00:07:21,150 --> 00:07:26,590
So I'm going to say if you're trying to delete if this style the user is causing is delete.

87
00:07:26,800 --> 00:07:28,680
Let's go ahead and do these things.

88
00:07:28,720 --> 00:07:33,490
The first thing you have to do is this you have to say whatever you're trying to delete.

89
00:07:33,490 --> 00:07:36,550
We also have to remove it from our array.

90
00:07:36,730 --> 00:07:42,340
Otherwise the application is going to crash simply because you've hit hard for instance six items in

91
00:07:42,340 --> 00:07:48,400
your array but only five cells in your table view and the app is going to pop back an error saying the

92
00:07:48,400 --> 00:07:53,440
number of items in your table view and the number of items in your array must be identical.

93
00:07:53,920 --> 00:07:55,540
Because I want to change my array.

94
00:07:55,540 --> 00:08:01,230
I'm going to have to change both of these to be value of us so valuable and valuable.

95
00:08:01,690 --> 00:08:07,990
And in here I'm going to go ahead and say if I'm trying to delete if we ordered the delete vote then

96
00:08:07,990 --> 00:08:16,340
search for if Index found that section is zero which means we are in the countryside then countries

97
00:08:16,370 --> 00:08:22,200
are a dot to remove the object they want to remove is index part that's wrong.

98
00:08:22,780 --> 00:08:30,250
So if for instance I'm trying to delete this one U.S. which is the item at index of one in the countries

99
00:08:30,580 --> 00:08:37,510
that is index mad that's a roll one in the index might that Section Zero so a section is zero index

100
00:08:37,510 --> 00:08:44,230
by the row is one I'm very moved that one from countries array which happens to be 0 and 1 it would

101
00:08:44,230 --> 00:08:45,260
be the US.

102
00:08:45,730 --> 00:08:51,550
So that's for the countries and then I'm going to go ahead and say else since I want to be able to delete

103
00:08:51,550 --> 00:09:00,700
from both of them citizenry data remove at a game index Mark DOT rule once you remove the object from

104
00:09:00,700 --> 00:09:07,870
the corresponding array being countries array or the citizenry we then have to actually delete the cell

105
00:09:07,900 --> 00:09:09,430
from our table view.

106
00:09:09,430 --> 00:09:16,780
So either of these two once they've done their work I'm going to have to say table view DOD delete rows

107
00:09:17,180 --> 00:09:19,380
and he's gonna say which rules do you want to delete.

108
00:09:19,400 --> 00:09:25,780
He's asking for an array of index parts I only have one index spot which is this one but they could

109
00:09:25,780 --> 00:09:31,850
delete multiple one of those I'm going to say make an array with only this one index man on the white

110
00:09:31,850 --> 00:09:38,560
table the bureau animation of Give Me Something such as let's say left so it moves to the left then

111
00:09:38,560 --> 00:09:45,070
collapses and deletes so we further remove the objects from the array and then we delete the roll and

112
00:09:45,070 --> 00:09:50,440
then the two of them will have the same number of objects if he had six rows and we deleted one we have

113
00:09:50,440 --> 00:09:55,530
five and if we had six objects in the area with deleted one we now have only five of them.

114
00:09:55,810 --> 00:10:01,510
So this time when we're on the application we should be able to swipe over some and by swiping we should

115
00:10:01,510 --> 00:10:02,580
be able to see the delete.

116
00:10:02,590 --> 00:10:07,730
But then we should be able to delete it accordingly delete and that one disappears.

117
00:10:07,750 --> 00:10:15,070
Once again delete either Piers it happens in every different section of the application as we try to

118
00:10:15,070 --> 00:10:18,940
delete when I pull here over in the RBC the delete button.

119
00:10:18,940 --> 00:10:22,940
Or when we pull here over the Mexico City you still see the delete button.

120
00:10:23,020 --> 00:10:28,810
What if you wanted to see which one of you are deleting or you wanted to see a different message in

121
00:10:28,810 --> 00:10:29,410
here.

122
00:10:29,410 --> 00:10:32,460
So for that I'm going to have to add another function here.

123
00:10:32,590 --> 00:10:39,500
That function again is a built in function called title for delete confirmation.

124
00:10:39,520 --> 00:10:46,300
So that is the title that appears for when you want to delete something in the table view for the index

125
00:10:46,300 --> 00:10:50,170
might you are trying to delete what you want to show.

126
00:10:50,170 --> 00:10:57,220
And here's what I want to show I want to see if index part that section is zero which means when the

127
00:10:57,220 --> 00:11:03,860
countries return this particular text the text says this delete.

128
00:11:04,390 --> 00:11:07,350
And after that delete it says this one.

129
00:11:07,360 --> 00:11:08,080
What is that.

130
00:11:08,080 --> 00:11:13,130
That is countries array at index path that role.

131
00:11:13,930 --> 00:11:19,610
So it's saying for instance if it was over India it says delete a space India.

132
00:11:19,810 --> 00:11:22,310
And then I want to have a question mark at the end of it.

133
00:11:22,360 --> 00:11:25,660
It is as if I'm asking Are you sure you want to delete this one.

134
00:11:25,720 --> 00:11:31,190
But I'm not going to make it as long as not because it becomes a little bit difficult to see it else

135
00:11:31,880 --> 00:11:37,600
I'm going to copy this pasted in there and here it says citizenry.

136
00:11:37,600 --> 00:11:43,990
So delete this one question mark and let's run the application nice again asking me for overwrite some

137
00:11:43,990 --> 00:11:48,160
of the methods automatically add the overwrite some of them they don't.

138
00:11:48,160 --> 00:11:52,780
So let's go ahead and run the application again and this time as we swipe and we try to delete.

139
00:11:52,780 --> 00:11:59,450
We should see a clearer message asking us Are you trying to delete this one delete India.

140
00:11:59,500 --> 00:12:05,350
And if it does fit is going to be within one line if it doesn't fit such as this one is actually going

141
00:12:05,350 --> 00:12:07,390
up within two lines it's saying delete.

142
00:12:07,390 --> 00:12:08,300
Mexico City.

143
00:12:08,320 --> 00:12:10,900
Yes I want to deleted delete.

144
00:12:10,900 --> 00:12:11,700
Mexico.

145
00:12:11,770 --> 00:12:12,170
Yes.

146
00:12:12,190 --> 00:12:14,510
I want to delete it.

147
00:12:14,650 --> 00:12:19,900
So far we have managed to show two different sections and we have been able to delete some items from

148
00:12:19,900 --> 00:12:20,660
them.

149
00:12:20,660 --> 00:12:27,220
Now what if we wanted to move some items are essentially what happens if we wanted to be able to rearrange

150
00:12:27,220 --> 00:12:29,010
our objects so to do that.

151
00:12:29,020 --> 00:12:31,460
I'm going to go in here into my view this lot.

152
00:12:31,680 --> 00:12:37,720
And in my view did Lord I'm going to go ahead and get rid of everything except for the line that says

153
00:12:38,050 --> 00:12:39,390
navigation item.

154
00:12:39,400 --> 00:12:39,990
Right.

155
00:12:39,990 --> 00:12:45,730
But by then item becomes an edit by then item if you're on the application right now.

156
00:12:45,760 --> 00:12:47,270
We will see the edit by then.

157
00:12:47,290 --> 00:12:53,290
I'm impressed at it by then we see a little icon next to each cell but they don't really do anything.

158
00:12:53,320 --> 00:12:56,420
When I press that we see that one we can press them.

159
00:12:56,440 --> 00:12:58,770
That is just going to show us that delete one.

160
00:12:58,840 --> 00:13:03,550
It doesn't show us anything for moving cells which is what we wanted to see.

161
00:13:03,550 --> 00:13:10,990
So to do that just like what we did for deleting which was can edit row we now have to add something

162
00:13:10,990 --> 00:13:13,270
that is called Can the move rule.

163
00:13:13,300 --> 00:13:16,400
So I'm going to come in here at the very bottom.

164
00:13:16,540 --> 00:13:26,530
I'm going to say can move roll at index that and I'm going to go ahead and say the return true.

165
00:13:26,530 --> 00:13:33,910
So this function alone it essentially says the cells can move but it doesn't say how they're going to

166
00:13:33,910 --> 00:13:36,620
move and how they're going to rearrange themselves.

167
00:13:36,670 --> 00:13:41,940
And for that we need two other methods in fact and I'm actually going to write both of them in here.

168
00:13:41,950 --> 00:13:46,140
So we get a sense of why we need to different methods in one of them.

169
00:13:46,150 --> 00:13:50,030
We have to decide Veer we are going.

170
00:13:50,380 --> 00:13:55,870
And then in the other function we have to go there what they mean by that is this if you're trying to

171
00:13:55,870 --> 00:14:01,340
rearrange items in yellow you're pulling the Mexico and you're dragging it over your tables.

172
00:14:01,390 --> 00:14:07,360
We need to know whether you can drop it within the cities or not or whether you can only drop it within

173
00:14:07,360 --> 00:14:08,340
the countries.

174
00:14:08,440 --> 00:14:11,380
Once that path is done when we do drop it.

175
00:14:11,380 --> 00:14:14,630
Now the arrangement of the items have changed.

176
00:14:14,740 --> 00:14:20,500
Now for instance if Mexico is setting up of us it means the items in the array they have a different

177
00:14:20,530 --> 00:14:21,290
order.

178
00:14:21,310 --> 00:14:23,430
So we have to know where we're going.

179
00:14:23,470 --> 00:14:29,080
And once we go there we have to read all their objects to make sure it reflects the current shape of

180
00:14:29,080 --> 00:14:30,100
our table view.

181
00:14:30,100 --> 00:14:45,020
So the first one is target index part time get index part for move raw at so this is a very long you

182
00:14:45,020 --> 00:14:46,180
know kind of function.

183
00:14:46,190 --> 00:14:49,560
I will explain to you what it does and why is it so long.

184
00:14:49,640 --> 00:14:57,800
It essentially says as you are trying to move there is the target in this spot for move from the roll.

185
00:14:57,800 --> 00:15:04,300
This is a source in next man unveils the proposed one as you are trying to drop it.

186
00:15:04,340 --> 00:15:06,280
Where does the application feel.

187
00:15:06,290 --> 00:15:12,710
It is the index pad that you are targeting because you can't manually sell your user that I get from

188
00:15:12,710 --> 00:15:15,380
index zero and go to index 5 4.

189
00:15:15,380 --> 00:15:17,000
You can say is that I get from here.

190
00:15:17,000 --> 00:15:18,890
Drop it somewhere on there.

191
00:15:19,040 --> 00:15:21,650
And that feels to be the index part at five.

192
00:15:21,680 --> 00:15:23,900
And if you add the water of the two of them.

193
00:15:23,900 --> 00:15:28,370
Then again the app has to decide for you whether it is index part four or five.

194
00:15:28,670 --> 00:15:31,980
And that becomes the proposed destination index spot.

195
00:15:32,270 --> 00:15:36,410
And what you usually want to do in here is this you want to say just return this.

196
00:15:36,410 --> 00:15:41,860
So you want to say return whatever is the proposed destination return.

197
00:15:41,900 --> 00:15:44,940
Because it's asking for an index map to be written.

198
00:15:44,990 --> 00:15:52,010
However there are situations that you don't want to drop it at the proposed destination index math for

199
00:15:52,010 --> 00:15:58,850
instance in this application in particular I don't want my user to be able to drag from countries into

200
00:15:58,850 --> 00:16:00,760
cities or vice versa.

201
00:16:00,770 --> 00:16:05,420
So if you're changing the sections I don't want him to be able to do that.

202
00:16:05,510 --> 00:16:12,350
To do that I'm going to go ahead and say if and I'm going to say source index part which is this guy.

203
00:16:12,590 --> 00:16:20,360
That section is not the same as a proposed destination index.

204
00:16:20,390 --> 00:16:29,990
That section if these two are not two within the same section do this return source just drop it back

205
00:16:29,990 --> 00:16:39,710
where you found it otherwise put it at the destination so by now a user can actually move rose and they

206
00:16:39,710 --> 00:16:45,350
can actually drag them around and they can find out where is the proposed destination for them whether

207
00:16:45,350 --> 00:16:48,920
they're going to go back to where they come from or they're going to go to a new place.

208
00:16:49,010 --> 00:16:57,110
But we haven't even told them what to do there how to go there and that is a function called move rule.

209
00:16:57,110 --> 00:16:59,000
So not can move road.

210
00:16:59,040 --> 00:17:03,950
So it's called Move roll at roll out.

211
00:17:03,980 --> 00:17:06,470
So that is the one that they want.

212
00:17:06,470 --> 00:17:11,660
So this one essentially works if you already can move.

213
00:17:12,110 --> 00:17:17,660
And if you already know what is the destination and spot that comes through dysfunction.

214
00:17:17,840 --> 00:17:23,900
If you do no worse off now then you can actually execute the movement and to do the execution.

215
00:17:23,900 --> 00:17:25,370
Here's what we're gonna be doing.

216
00:17:25,370 --> 00:17:26,550
Let me add the overwrite.

217
00:17:26,570 --> 00:17:34,450
So that error shuts up if the source index path that section was zero.

218
00:17:34,460 --> 00:17:39,530
If you're moving within the first section so let's do some things in there.

219
00:17:39,530 --> 00:17:45,910
Else you have to do other things for the cities for the countries here's what they have to do.

220
00:17:45,920 --> 00:17:51,560
I have to say let's find the element that we are trying to solve.

221
00:17:51,560 --> 00:18:00,500
To do that I'm going to say let let's call it element that becomes country as array from or source index

222
00:18:00,500 --> 00:18:02,380
part dot or.

223
00:18:02,600 --> 00:18:06,130
So we find the object we are trying to move around.

224
00:18:06,260 --> 00:18:11,750
Once we do that we're going to say countries are array dots removed and the object we're removing is

225
00:18:11,750 --> 00:18:13,920
source index card that's raw.

226
00:18:14,000 --> 00:18:16,350
So we get rid of that in the array.

227
00:18:16,520 --> 00:18:24,620
Once that is taking care of and then go ahead and say countries agree that insert and inserting a new

228
00:18:24,620 --> 00:18:32,060
element which is the old element at a new location which is the destination index part that rule.

229
00:18:32,090 --> 00:18:37,310
So essentially in our array we remove one object and replace it somewhere else.

230
00:18:37,310 --> 00:18:42,010
Imagine if the source index match was one destination was three.

231
00:18:42,050 --> 00:18:44,870
So here 1 and 3.

232
00:18:44,870 --> 00:18:46,610
Ok so here's what we are doing.

233
00:18:47,780 --> 00:18:50,490
So this is one we are deleting it.

234
00:18:50,750 --> 00:18:53,740
This is 0 1 2 3.

235
00:18:53,760 --> 00:18:55,100
You're pasting it in there.

236
00:18:55,250 --> 00:19:00,320
So you're reordering the objects but I'm not going to do that right now we're going to go back to what

237
00:19:00,320 --> 00:19:00,800
we had

238
00:19:03,530 --> 00:19:05,830
so here we got down on taking care of.

239
00:19:06,020 --> 00:19:11,760
And of course we have to repeat exactly the same thing for the other section except date will be city's

240
00:19:11,790 --> 00:19:14,150
array for everything.

241
00:19:14,180 --> 00:19:19,910
So again if we're moving we find the source index cards the role in the city's array and we do everything

242
00:19:19,910 --> 00:19:20,820
in the cities.

243
00:19:21,050 --> 00:19:23,270
Let's run the application up until this point

244
00:19:29,150 --> 00:19:35,210
so now when I pressed the Edit By then we get these little icons on the right that allow us to rearrange

245
00:19:35,210 --> 00:19:41,270
objects and I can essentially bring something in here and as I'm moving them the app automatically finds

246
00:19:41,270 --> 00:19:43,460
the proposed destination.

247
00:19:43,580 --> 00:19:49,430
And when I drop it it places in there rearranges my array and if I try to bring something for instance

248
00:19:49,430 --> 00:19:53,330
from the cities New York into the countries it doesn't along.

249
00:19:53,330 --> 00:20:00,350
It goes back to its source within the right section as showed one more time if I tried to push Canada

250
00:20:00,410 --> 00:20:01,480
all the way at the bottom.

251
00:20:01,490 --> 00:20:05,640
It actually works but Canada into cities it doesn't work.

252
00:20:05,700 --> 00:20:08,430
And once I'm done I'm going to had the Done button.

253
00:20:08,480 --> 00:20:13,770
Now there's only one more thing I want to show you and that's just to do things a little bit simpler.

254
00:20:13,870 --> 00:20:16,240
You don't really have to do any of these things.

255
00:20:16,280 --> 00:20:20,760
This whole process of doing if it is a section do this else too.

256
00:20:20,760 --> 00:20:23,510
The other thing it seems a little bit tedious.

257
00:20:23,540 --> 00:20:26,450
What if we could simplify this process.

258
00:20:26,450 --> 00:20:28,970
Now the good news is we absolutely could do that.

259
00:20:28,970 --> 00:20:34,090
And if you're working on a smaller application you could actually have an array of arrays.

260
00:20:34,170 --> 00:20:39,860
If you're having a slightly larger application you could essentially have a dictionary of arrays in

261
00:20:39,860 --> 00:20:42,710
here I'm actually going to go ahead and have an array of arrays.

262
00:20:42,720 --> 00:20:54,520
I'm going to say array of arrays which is of the type array of array of strings.

263
00:20:54,650 --> 00:20:59,840
So this becomes a little bit of a complicated process but essentially it tells me what's going on.

264
00:20:59,960 --> 00:21:05,540
It is an array of arrays of strings and why is it like that.

265
00:21:05,540 --> 00:21:13,550
Because array of arrays soon enough in our view this load becomes country's array and cities array just

266
00:21:13,550 --> 00:21:14,480
like that.

267
00:21:14,480 --> 00:21:20,960
So that really helps me placing everything within one array and you cannot do the initialization in

268
00:21:20,960 --> 00:21:26,210
here in here if you try to do that if you try to say put this part in here.

269
00:21:26,210 --> 00:21:31,430
It's actually not going to work is going to give you an error saying that you cannot initialize objects

270
00:21:31,430 --> 00:21:37,780
in here cannot use our instance member routine property initialization.

271
00:21:37,790 --> 00:21:40,730
So you must do it within here.

272
00:21:40,820 --> 00:21:45,200
So I'm going to get rid of all of these I'm going to push it back the way it used to be and now we have

273
00:21:45,200 --> 00:21:50,750
an array of arrays that has countries and cities and let's see how that's going to simplify my life

274
00:21:51,230 --> 00:21:58,780
in the number of sections I'm going to say return array of array that counts in the number of rows I'm

275
00:21:58,780 --> 00:22:09,380
going to say get rid of everything and do this say return array of arrays find the right section and

276
00:22:09,380 --> 00:22:14,810
find the right count of that because I know there is an array written here but there the section is

277
00:22:14,810 --> 00:22:22,190
0 over this section is 1 when it comes to here when we are doing this cell for raw at index Mart I don't

278
00:22:22,190 --> 00:22:29,030
need to go through countries and cities independently I'm gonna do this I'm going to say sell that text

279
00:22:29,030 --> 00:22:38,960
label becomes array of arrays not that array of arrays then from that find index part that section so

280
00:22:38,960 --> 00:22:47,260
we end up in one of the two arrays from that which is an array itself find index part got to roll.

281
00:22:47,360 --> 00:22:54,830
So it essentially becomes one array which is for instance the countries from that a certain location

282
00:22:55,220 --> 00:23:00,020
and other array which if the section is one becomes the cities from that.

283
00:23:00,020 --> 00:23:01,680
This is a road that you're looking for.

284
00:23:02,030 --> 00:23:05,690
So that really helps this part we can't really change it on this.

285
00:23:05,690 --> 00:23:10,970
We had a dictionary that had keys for the both countries and the cities.

286
00:23:10,970 --> 00:23:17,570
Here again will end up in a place that depending on which one we are trying to edit we remove that one.

287
00:23:17,580 --> 00:23:24,920
So I'm going to say array of arrays are and I'm going to go through the index pad that section then

288
00:23:24,980 --> 00:23:33,160
I'm going to say remove and remove is going to be index pad dot roll so we can delete all of these things

289
00:23:33,170 --> 00:23:35,200
it simplifies our life in here as well.

290
00:23:35,660 --> 00:23:39,290
Then we go in here which says which one do you want to delete.

291
00:23:39,290 --> 00:23:45,680
Once again we will have return and then the return I'm going to say delete what they want to delete

292
00:23:45,740 --> 00:23:46,370
is this

293
00:23:49,430 --> 00:23:57,530
array of arrays and from that I want to get the index pad that section once I found that I want to get

294
00:23:57,530 --> 00:24:00,810
the one that says index dot rule.

295
00:24:00,920 --> 00:24:03,200
So I don't need any of these guys.

296
00:24:03,260 --> 00:24:10,440
They would need is this delete find the right array from their res and find the right set of the front

297
00:24:11,150 --> 00:24:17,480
then I can move wrong we don't need to do anything this part we don't need to do anything and here once

298
00:24:17,480 --> 00:24:29,180
again life would be a little bit simpler by saying let them become array of arrays index part and that's

299
00:24:29,180 --> 00:24:35,150
going to be the source index part source index part of that section

300
00:24:43,370 --> 00:24:47,240
that section and then from there.

301
00:24:47,270 --> 00:24:52,220
I want to get the source index part diet to roll.

302
00:24:52,250 --> 00:24:57,710
So we find this specific elements that we are trying to remove or we're trying to move to the other

303
00:24:57,710 --> 00:24:58,640
place.

304
00:24:58,640 --> 00:25:05,830
Then I'm going to go ahead and say reauthorize source index smart diet section.

305
00:25:05,840 --> 00:25:11,180
Now we find the right are a countries or the cities that remove.

306
00:25:11,530 --> 00:25:17,070
And the one they want to remove is the one that they want to rearrange which is essentially source index

307
00:25:17,070 --> 00:25:19,800
smart diet to roll once again.

308
00:25:19,820 --> 00:25:27,020
So from the array of arrays removed that and then we're gonna go ahead and say array of arrays source

309
00:25:27,050 --> 00:25:36,080
index math dart section dart insert and I want to insert the elements at destination.

310
00:25:36,260 --> 00:25:41,510
Now some of the things I did in here it might seem that I'm actually making things more complicated

311
00:25:41,570 --> 00:25:44,020
especially if you are newer at programming.

312
00:25:44,150 --> 00:25:45,410
You might feel that OK.

313
00:25:45,440 --> 00:25:52,010
This isn't easier by any stretch is actually more complicated but once you get a better sense of programming

314
00:25:52,010 --> 00:25:57,220
and you feel a little bit more comfortable you will know that you will prefer less code.

315
00:25:57,350 --> 00:26:03,410
And even if it means more complicated code such as things such as this one in saying that you could

316
00:26:03,410 --> 00:26:09,830
actually always go ahead and say in any of these I'm going to convert that into a variable so I know

317
00:26:09,830 --> 00:26:11,480
exactly what I'm talking about.

318
00:26:11,600 --> 00:26:14,850
I didn't do that in here but that would be another option for you.

319
00:26:14,900 --> 00:26:19,550
Let me run the application to make sure that everything we just did is actually functioning and nothing

320
00:26:19,550 --> 00:26:22,410
has actually gone wrong which I don't really think so.

321
00:26:22,490 --> 00:26:24,300
But just sort of we are short of it.

322
00:26:24,380 --> 00:26:31,670
So now we can delete and we can actually edit and we can move or we cannot move within sections but

323
00:26:31,670 --> 00:26:37,280
we can certainly move in a section and that's all we needed to doing here.

324
00:26:37,280 --> 00:26:43,640
So these are different methods that you use for you know more advanced table view operations.

325
00:26:43,640 --> 00:26:46,190
Let's keep it up to here and move on to our next lesson.
