1
00:00:00,600 --> 00:00:06,300
They come back again in this this and I will show you two different ways of running a search within

2
00:00:06,300 --> 00:00:12,130
a table view in the first method they will show you how to filter the content of the table view.

3
00:00:12,180 --> 00:00:17,610
So he chose only doors that you're interested in and the other method able to show you how to add a

4
00:00:17,610 --> 00:00:25,500
search display result controller that shows you a table view on top of any view that shows you the results

5
00:00:25,500 --> 00:00:26,490
that you're asking for.

6
00:00:26,820 --> 00:00:30,300
So kind of a full on lesson and let's get this started.

7
00:00:30,300 --> 00:00:31,600
I'm going to go to export.

8
00:00:31,650 --> 00:00:33,540
I'm going to start a new application.

9
00:00:33,570 --> 00:00:43,050
I'm going to call it search and table view and in here once I have everything I'm going to head into

10
00:00:43,050 --> 00:00:44,270
my storyboard.

11
00:00:44,310 --> 00:00:47,310
And this time I'm not going to use a table view controller.

12
00:00:47,310 --> 00:00:49,530
I'm actually going to use a table view.

13
00:00:49,770 --> 00:00:57,980
So we're going yeah I'd say I have a table view which is this guy I'm going to place it here.

14
00:00:58,030 --> 00:01:06,120
I take that like this then I'm going to go ahead and add a table view cell which I need for my table

15
00:01:06,120 --> 00:01:08,340
view right when I'm here.

16
00:01:08,340 --> 00:01:16,160
I'm gonna go ahead for my cell and say it's the style as basic as identifier is cell I.D..

17
00:01:16,890 --> 00:01:19,370
I will also add a new search bar.

18
00:01:19,800 --> 00:01:26,550
So a search bar I'm gonna add in here and I could actually select both the search bar and the table

19
00:01:26,550 --> 00:01:31,020
view go down in here and say add the missing constraints.

20
00:01:31,020 --> 00:01:37,680
This doesn't to my opinion are the best set of constraints but for my purpose it actually does the work.

21
00:01:37,710 --> 00:01:43,770
The next thing I want to do in my storyboard is setting the table view delegate and data source to be

22
00:01:43,770 --> 00:01:45,390
on my view controller.

23
00:01:45,710 --> 00:01:52,480
I want to hold control and drive over a year say data source do the same thing we delegate.

24
00:01:52,620 --> 00:01:54,420
So now both of them are set.

25
00:01:54,540 --> 00:02:01,770
And finally I'm going to go to my assistant window get myself some better space in here and say this

26
00:02:01,770 --> 00:02:05,220
is actually my search bar.

27
00:02:05,220 --> 00:02:09,110
It is of the type you I search for Connect.

28
00:02:09,390 --> 00:02:12,280
And of course this one is my table view.

29
00:02:12,510 --> 00:02:16,410
So my table view all right.

30
00:02:16,440 --> 00:02:18,740
So so far we haven't done anything that is new.

31
00:02:18,780 --> 00:02:24,510
But now let's go ahead into a view controller and I'm gonna assume that my table view shows me the names

32
00:02:24,510 --> 00:02:25,800
of some cities.

33
00:02:25,920 --> 00:02:31,450
And every time that they search in my search what it filters them based on what I'm asking for it.

34
00:02:31,500 --> 00:02:39,120
So I'm really going here and say let the cities array be and this time I'm going to have to add a few

35
00:02:39,120 --> 00:02:40,160
more cities.

36
00:02:40,160 --> 00:02:48,660
So I'm going to say New York maybe Tokyo maybe thrown all

37
00:02:52,140 --> 00:03:06,500
over and say the same genus that's going to spend it a whole Chicago reel.

38
00:03:06,730 --> 00:03:12,880
So I have some cities in here in my city is array and then but I'm going to have to do is I'm going

39
00:03:12,880 --> 00:03:15,040
to have to add the two protocols in here.

40
00:03:15,070 --> 00:03:22,380
So I'm going to say I need a new table view a data source and I need a you a table view delegate.

41
00:03:22,930 --> 00:03:27,230
And if you remember there are two methods that we must conform to them.

42
00:03:27,340 --> 00:03:29,160
I'm going to add both of those methods.

43
00:03:29,170 --> 00:03:40,300
One of them is called number of rows in sections and the other one is going to be set for raw at index

44
00:03:40,300 --> 00:03:41,000
spot.

45
00:03:41,020 --> 00:03:46,010
So these are the same things that we have been doing over and over and over in this section.

46
00:03:46,130 --> 00:03:50,060
That number of rows is going to be citizenry that count.

47
00:03:50,080 --> 00:03:51,850
I have to of course return that.

48
00:03:52,660 --> 00:04:01,630
And then for my cell I'm going to say let's sell to be table view that the Q reusing cell I.D. Let me

49
00:04:01,630 --> 00:04:09,510
get myself into the space in here and then go ahead and say cell that next level.

50
00:04:09,550 --> 00:04:16,650
That text becomes the citizenry object that index that's raw and return.

51
00:04:16,650 --> 00:04:23,950
That said so by now we should have a table view that shows us these these objects and it's telling me

52
00:04:23,950 --> 00:04:25,630
Are you sure this thing exists.

53
00:04:25,630 --> 00:04:32,620
I know this it is this or less force on it and we don't need to have that option optional that anymore.

54
00:04:32,630 --> 00:04:37,300
Let me run the application just to get some confidence that we're in the right track by now we should

55
00:04:37,300 --> 00:04:43,630
be able to see everything that we have done before except that this time we have a little more you know

56
00:04:43,630 --> 00:04:48,070
objects in our table view and if it all works we should see all of these.

57
00:04:48,220 --> 00:04:55,330
Now the next call is tapping in here typing something in the search and we want these guys to filter

58
00:04:55,330 --> 00:04:57,760
based on the search criteria.

59
00:04:57,760 --> 00:04:58,810
So let's go ahead in here.

60
00:04:59,230 --> 00:05:05,270
So for doing the search I'm going to assume that we have another array that is the array of the filter

61
00:05:05,270 --> 00:05:09,030
of the content and we showed that in our table view.

62
00:05:09,070 --> 00:05:14,620
So essentially and let's go in here and say once we have the citizenry I'm also going to go ahead and

63
00:05:14,620 --> 00:05:16,290
have very of them.

64
00:05:16,320 --> 00:05:24,820
Let's call it filter array which is going to be a String array and is currently empty.

65
00:05:25,480 --> 00:05:30,310
So we have the filter array and we have to use it instead of the city's array.

66
00:05:30,340 --> 00:05:36,390
So I'm going to say everything the table view is going to show its numbers make it based on the filtered

67
00:05:36,400 --> 00:05:41,830
array and everything that you want to show a cell make it based on the filter array but I'm also going

68
00:05:41,830 --> 00:05:48,550
to go ahead into my view did Lord and say right at the very beginning filter array is the same as the

69
00:05:48,550 --> 00:05:49,750
city's array.

70
00:05:49,780 --> 00:05:55,330
So at the beginning there is no search happening just duplicate everything in the city is a place it

71
00:05:55,350 --> 00:05:56,670
in the film territory.

72
00:05:56,710 --> 00:06:01,930
So if you're run the application again we should see exactly the same thing as before we have the array

73
00:06:01,930 --> 00:06:04,790
being populated from the city's array.

74
00:06:04,810 --> 00:06:10,360
And that is being used to show us the items in our table view now that we have that you could actually

75
00:06:10,360 --> 00:06:13,780
go ahead and run the search in here to do that.

76
00:06:13,780 --> 00:06:16,430
I'm going to go ahead and say you may view this.

77
00:06:16,440 --> 00:06:24,520
Lord I'm going to say my search what dot delegate which is of the type you I search for delegate becomes

78
00:06:24,580 --> 00:06:28,900
self since I'm doing that I have to conform to that protocol.

79
00:06:28,930 --> 00:06:32,540
So you I search for delegate.

80
00:06:32,710 --> 00:06:34,110
No they have the delegate.

81
00:06:34,120 --> 00:06:36,000
I could actually use one of its methods.

82
00:06:36,010 --> 00:06:42,880
That is very similar to the text field text changed and that is the way that the very by them that's

83
00:06:42,880 --> 00:06:47,040
going to become text did change.

84
00:06:47,080 --> 00:06:50,620
So it is search for you I search by text.

85
00:06:50,620 --> 00:06:56,650
Did that change each time that the text value and the search bar actually changes if you want to filter

86
00:06:56,680 --> 00:07:00,640
or array based on the criteria that recently has been added there.

87
00:07:01,210 --> 00:07:07,300
So in text did change the first thing I want to do is I want to say filter array becomes a new copy

88
00:07:07,300 --> 00:07:08,890
of the city's array.

89
00:07:08,890 --> 00:07:11,310
I want a start from a fresh copy.

90
00:07:11,410 --> 00:07:19,900
Then when I go ahead and say as the text changes if the text value is not empathy because it's possible

91
00:07:19,900 --> 00:07:24,420
that when the text changes you're passing the backspace and you're deleting everything.

92
00:07:24,430 --> 00:07:28,150
So what we want to make sure that we are not on an empty mode.

93
00:07:28,150 --> 00:07:36,290
So I'm going to say if search bar dot text is empty.

94
00:07:36,400 --> 00:07:42,060
If that is not the case then let's go ahead and filter our array.

95
00:07:42,340 --> 00:07:47,110
So I'm going to say if that wasn't the case and we have to make sure that this is a non optional value

96
00:07:47,440 --> 00:07:50,180
so I could essentially allow it to autocomplete.

97
00:07:50,260 --> 00:07:57,250
So is gonna make that the entire thing the search for exists the text to exist and is not empathy so

98
00:07:57,390 --> 00:07:59,180
is a force on a loved one.

99
00:07:59,640 --> 00:08:06,210
So in that I'm going to say if that was the case if there is some text visible in our search for text

100
00:08:06,600 --> 00:08:07,680
then here's what you want to do.

101
00:08:07,680 --> 00:08:13,440
You want to say filter array becomes city's array dot filter.

102
00:08:14,020 --> 00:08:19,500
And now we have to filter it using a certain closure and the closure I want to use is this I want to

103
00:08:19,500 --> 00:08:24,900
say there is something called N3 and free of the type a string.

104
00:08:24,900 --> 00:08:29,270
And here is how I want to return it because it has to return a boolean value.

105
00:08:29,340 --> 00:08:36,870
So in case this filtering is correct for this particular entry it gets added to the filter array.

106
00:08:36,960 --> 00:08:38,610
What is the condition for that.

107
00:08:38,610 --> 00:08:48,970
I'm gonna say the condition for that is this return entry does contains if it does contain the value

108
00:08:48,970 --> 00:08:52,460
from search bar dot text.

109
00:08:52,540 --> 00:08:59,920
So for instance if your entry value is this one New York and here you have a value that you have enter

110
00:08:59,930 --> 00:09:08,350
such as n letter N if that n exists it contains with an entry that returns as true and since it returns

111
00:09:08,350 --> 00:09:13,780
through through the filter it gets added to the filter array otherwise it doesn't.

112
00:09:13,780 --> 00:09:20,530
Once that entire process is done I'm going to go ahead and say s that my table view that the reload

113
00:09:20,560 --> 00:09:24,230
data because now we have a new filter array.

114
00:09:24,420 --> 00:09:26,190
The square then run this application.

115
00:09:28,410 --> 00:09:31,470
So now we have our table view and we have our search bar.

116
00:09:31,470 --> 00:09:35,320
And if I type in it actually filters it based on doors.

117
00:09:35,340 --> 00:09:41,140
If I type t makes it based on those guys I want to show you one other thing that we could do in here.

118
00:09:41,340 --> 00:09:48,360
If I type for instance n I get the right thing but if I type for instance e it doesn't show me the right

119
00:09:48,360 --> 00:09:54,360
thing even though I have characters in here that they have lower case e and anytime that you're running

120
00:09:54,360 --> 00:09:58,730
a search is actually better if you eliminate the capitalization.

121
00:09:58,770 --> 00:10:07,530
So to do that I'm going to go ahead and say entry dart to lower case if it that contains whatever we

122
00:10:07,530 --> 00:10:14,820
have in the text got to lower cased and that's because the lower case version of letters might be identical

123
00:10:14,820 --> 00:10:16,280
to each other for instance.

124
00:10:16,350 --> 00:10:22,230
All of these letters e or E are exactly the same or I or I.

125
00:10:22,590 --> 00:10:26,070
But if we were comparing them against each other they would be different.

126
00:10:26,070 --> 00:10:32,760
But if we compare them lower case they both become E N E and the other ones they become I and I and

127
00:10:32,760 --> 00:10:33,960
so on and so forth.

128
00:10:34,230 --> 00:10:40,200
So let me read on the application and now we should be able to type any combination of capital or lowercase

129
00:10:40,200 --> 00:10:42,920
letters and we should still be able to filter them.

130
00:10:43,170 --> 00:10:49,620
So in here I'm going to say New York perfect as well as a capital E which is still gets me all the results

131
00:10:49,650 --> 00:10:56,730
that they do have an Eevee team them and that's pretty much you're doing a search of it in a table view

132
00:10:56,850 --> 00:10:58,080
and that's going to get us there.

133
00:10:58,500 --> 00:11:04,700
Now this was doing a search v Tina table view that we already have a storyboard.

134
00:11:04,710 --> 00:11:09,600
Now what I'm going to do is I'm going to make a new application where we don't actually have a table

135
00:11:09,600 --> 00:11:15,480
view but we have a list of items and we want to be able to filter through those items and represents

136
00:11:15,480 --> 00:11:16,930
them in a table view.

137
00:11:16,950 --> 00:11:21,810
So in the second iteration we don't actually have a table view in our application.

138
00:11:21,840 --> 00:11:27,270
What we have is perhaps a map or just a view controller that has some items.

139
00:11:27,270 --> 00:11:32,370
But do we know that our user has access to a set of different items and what we want to be able to do

140
00:11:32,370 --> 00:11:38,010
is we want to be able to search for items based on a string of text and we endorse the ones that they

141
00:11:38,010 --> 00:11:39,540
match our criteria.

142
00:11:39,540 --> 00:11:41,850
We want to see them in a table.

143
00:11:42,210 --> 00:11:45,540
So to do that I want to go ahead and start a new application.

144
00:11:45,540 --> 00:11:52,350
I'm going to call this application search controller app simply because in this application we benefit

145
00:11:52,350 --> 00:11:55,680
from something that's called a search controller.

146
00:11:55,680 --> 00:12:01,590
So what's happening in here is this I have a view controller in my storyboard that could have essentially

147
00:12:01,590 --> 00:12:02,400
anything in it.

148
00:12:02,400 --> 00:12:07,580
The one thing they really need to have is a search bar in it and I'm not gonna make the search part

149
00:12:07,580 --> 00:12:13,300
of it in this story what I'm rather going to make it programmatically but they need to assign a container

150
00:12:13,300 --> 00:12:14,250
of you for it.

151
00:12:14,250 --> 00:12:20,310
So I'm going to go in here and say I need a UI view and this UI view and when a place it somewhere up

152
00:12:20,310 --> 00:12:23,730
here you can obviously set all the constraints on what not.

153
00:12:23,730 --> 00:12:29,150
But for me that's all I want to do I want to place it in here and say it has a light gray bank on.

154
00:12:29,340 --> 00:12:35,790
This is where my search bar is going to be and I'm going to head back to my assistant window in here.

155
00:12:35,820 --> 00:12:38,710
I'm going to make a an outlet for this guy.

156
00:12:38,730 --> 00:12:44,310
Say this is search bar container view.

157
00:12:44,460 --> 00:12:50,060
So that's all I want to do in my storyboard assuming that you will have other things in your story but

158
00:12:50,070 --> 00:12:55,650
most likely you will have a map or anything of the sort that can have so many different items that you

159
00:12:55,650 --> 00:12:57,390
can search within them.

160
00:12:57,390 --> 00:13:02,460
So I'm going to head back to my view controller and in here I'm going to go ahead and say Let me get

161
00:13:02,460 --> 00:13:04,480
better formatting first.

162
00:13:04,680 --> 00:13:09,590
And the first thing I want to do is this I want to say I have a value event and I'm going to call it

163
00:13:09,580 --> 00:13:15,720
the search controller which is of the type you I search controller.

164
00:13:15,780 --> 00:13:22,850
Now a search controller is essentially a type of outlet that has a search bar as well as a result view

165
00:13:22,860 --> 00:13:23,830
controller.

166
00:13:23,850 --> 00:13:27,510
So it shows you some results after he does the search.

167
00:13:27,540 --> 00:13:33,360
And since I want to see the results in a table view controller I need another outlet which is of the

168
00:13:33,360 --> 00:13:36,240
type table view controller to do that.

169
00:13:36,260 --> 00:13:41,700
I'm actually going to go ahead and make making you find I'm gonna say command and I'm going to say this

170
00:13:41,700 --> 00:13:44,280
is after type you a table of your controller.

171
00:13:44,280 --> 00:13:47,520
I'm going to call it results table view controller

172
00:13:51,350 --> 00:13:57,130
now now this is a table of your controller that doesn't have a storyboard outlet associated with it.

173
00:13:57,160 --> 00:14:03,340
We will initialize this programmatically but we still need to do everything that we usually do for a

174
00:14:03,340 --> 00:14:04,080
table view.

175
00:14:04,120 --> 00:14:10,440
So to do that I'm let go ahead and say Here I have something called value but unless call it the results

176
00:14:10,570 --> 00:14:16,990
array which is in this case for what I'm doing is after type a string and is empty right at the very

177
00:14:16,990 --> 00:14:18,570
beginning so there's nothing in it.

178
00:14:18,570 --> 00:14:24,050
At the very very beginning the number of sections I'm actually going to remove for the number of the

179
00:14:24,040 --> 00:14:29,330
rows I'm going to say it is actually a result array does count.

180
00:14:29,680 --> 00:14:34,600
And then the only other method I necessarily must have is the cell for rows.

181
00:14:34,630 --> 00:14:41,260
I'm going to say that one that we get rid of everything else for that one I'm going to say I have a

182
00:14:41,260 --> 00:14:48,850
cell that said is using cell I.D. and then I'm going to say cell not text labor.

183
00:14:48,940 --> 00:14:54,030
That text becomes results array index part.

184
00:14:54,060 --> 00:14:55,300
That's right.

185
00:14:55,540 --> 00:15:01,810
Now you might be wondering is the cell I.D. coming from because we don't have anything for the results

186
00:15:01,810 --> 00:15:06,330
table view controller in our a storyboard and that's a very valid question.

187
00:15:06,350 --> 00:15:12,900
We have to essentially register a cell to be used for this table if you control it and to do that.

188
00:15:12,910 --> 00:15:18,490
I'm going to go ahead and say I first need to make myself a table view said so I'm going to start new

189
00:15:18,490 --> 00:15:24,380
unified command and go to a view user interface type and this one I'm going to essentially call it the

190
00:15:24,380 --> 00:15:26,060
result cell.

191
00:15:26,570 --> 00:15:33,910
And as you can imagine in here I don't need a view but they do need is a UI table view cell essentially.

192
00:15:33,940 --> 00:15:40,030
So I need one of these guys and this is the cell I want to use for every resource that they find this

193
00:15:40,030 --> 00:15:41,030
cell that they have.

194
00:15:41,050 --> 00:15:48,100
I'm going to call it to be cell I.D. for its identifier and I'm going to go ahead and say its type is

195
00:15:48,100 --> 00:15:50,050
essentially basic type.

196
00:15:50,290 --> 00:15:56,180
That's all I have to do in terms of the most basic stuff you need to do to have a new cell.

197
00:15:56,200 --> 00:16:01,240
Now the next thing and the more important thing is you have to go to your resource table view controller

198
00:16:01,390 --> 00:16:04,260
in your view did Lord you have to register it.

199
00:16:04,270 --> 00:16:10,570
You essentially have to say this table view will use this kind of cell and we do it like this.

200
00:16:10,600 --> 00:16:15,740
I'm going to say let me but to be you I never.

201
00:16:16,300 --> 00:16:22,320
And then after type nib name is going to be this name resolved cell.

202
00:16:22,370 --> 00:16:24,310
And we don't have a bundle for it.

203
00:16:24,370 --> 00:16:30,760
So we got the net we got access to this file and then I'm going to go ahead and say self dots table

204
00:16:30,760 --> 00:16:40,710
view dot register in the register I'm going to say register this guy this number for identifier sell

205
00:16:40,800 --> 00:16:41,560
I.D..

206
00:16:41,680 --> 00:16:48,710
So what this means is they have a resolved cell outlet that they want to register as one of their prototype

207
00:16:48,710 --> 00:16:50,840
cells for my table view.

208
00:16:50,890 --> 00:16:56,770
So it would be very similar to you dragging in your table you sell to your table view controller and

209
00:16:56,770 --> 00:17:02,770
each time you do it you add a new I.D. for it and it essentially becomes of one of the prototype cells

210
00:17:02,800 --> 00:17:04,250
that you have access to.

211
00:17:04,300 --> 00:17:10,600
And now since it is registered as viewed it Lord we have access to it because obviously use it in here.

212
00:17:10,600 --> 00:17:15,570
So by now we have a table view that has a results array has the right cell.

213
00:17:15,640 --> 00:17:21,310
And if we can call it somebody it can show us the results that we want but now we have to essentially

214
00:17:21,310 --> 00:17:24,430
use these results table view controller to do that.

215
00:17:24,430 --> 00:17:29,700
I'm going to go to my view controller and I'm going to initialize my results.

216
00:17:29,700 --> 00:17:35,160
Controller of the type results table view controller.

217
00:17:35,410 --> 00:17:40,400
So I have a new variable of that type and then than I had in my view did law.

218
00:17:40,460 --> 00:17:43,930
The first thing I'm gonna do is I'm going to say my results.

219
00:17:43,930 --> 00:17:50,600
Controller becomes a results table view controller and that gets allocated and initialize.

220
00:17:50,650 --> 00:17:57,980
Then I'm gonna go ahead and say this guy my search controller becomes a UI search controller.

221
00:17:58,120 --> 00:18:03,060
I'm one of the initialization is is initialize with a certain view controller.

222
00:18:03,130 --> 00:18:09,310
So I'm going to say my search controller values my result controller which is a table view controller

223
00:18:09,760 --> 00:18:12,160
has its results controller.

224
00:18:12,190 --> 00:18:19,720
So once it loads is gonna show me the results in here in this kind of view controller you could theoretically

225
00:18:19,720 --> 00:18:25,630
use any kind of viewpoint on in there but most often what they have seen is people use a table view

226
00:18:25,630 --> 00:18:33,410
controller because you kind of want to be able to see the results basically by sellers or by your rows.

227
00:18:33,490 --> 00:18:38,470
You could use a collection you can tour as well that is something that would be the study in this section

228
00:18:38,740 --> 00:18:42,610
but most likely you want to use a table view controller in here.

229
00:18:42,610 --> 00:18:48,200
So once they have that the next thing I have to do is this I have to say my search bar container view

230
00:18:48,220 --> 00:18:56,510
over I will see the search will have a sub view and that sub view is the search controller not search

231
00:18:56,510 --> 00:18:57,020
bar.

232
00:18:57,260 --> 00:19:03,460
So I want to add the search bar from my search controller to be between my search container review.

233
00:19:03,530 --> 00:19:08,180
If you don't recall a search container of you was this little you review that they made in here so I

234
00:19:08,180 --> 00:19:11,610
can embed my search bar of it in here.

235
00:19:11,630 --> 00:19:16,280
The next thing I'm going to do I'm gonna say let's set the delegates so search controller.

236
00:19:16,490 --> 00:19:23,060
And when I say DOD delegate shows off the type you a search controller delegate becomes self.

237
00:19:23,120 --> 00:19:25,910
So I'm going to have to add that so that's one.

238
00:19:26,440 --> 00:19:33,770
So let's go ahead in here and say you I search controller delegate that's added.

239
00:19:33,770 --> 00:19:40,730
Let me reformat everything you a search controller delegate gets rid of this extra spaces and the next

240
00:19:40,730 --> 00:19:45,630
thing I want to add is another delegation here which is the search result updated.

241
00:19:45,930 --> 00:19:50,310
So I'm gonna say search controller that search result update her.

242
00:19:50,480 --> 00:19:52,570
It wants to update it in here.

243
00:19:52,760 --> 00:19:56,860
So the updates have to appear from some sort of a function in here.

244
00:19:57,020 --> 00:20:02,210
And the moment we do that is obviously going to tell us you need to embed UI search results updating.

245
00:20:02,500 --> 00:20:09,560
And then add that one and that delegate has a required method which is essentially the update search

246
00:20:09,560 --> 00:20:10,640
for results.

247
00:20:10,640 --> 00:20:15,370
So it says update search results for this UI search controller.

248
00:20:15,420 --> 00:20:19,020
And in saying so what do you want to happen every time that we update.

249
00:20:19,100 --> 00:20:20,730
I'm going to write it down first.

250
00:20:20,780 --> 00:20:31,480
I want to filter my guidance and I want to reload the table view from the results view controller.

251
00:20:31,630 --> 00:20:36,310
I want to present the results view controller.

252
00:20:36,440 --> 00:20:40,670
So a lot of things that we have to do the very first thing we have to do is we have to feel there are

253
00:20:40,670 --> 00:20:46,700
items but they don't actually have any items in here because we don't have any array of items in a real

254
00:20:46,700 --> 00:20:47,720
life application.

255
00:20:47,720 --> 00:20:52,790
This would be something that comes to you from a network that is something we will see in a few sections

256
00:20:52,790 --> 00:20:55,490
from now or you will have some static values.

257
00:20:55,700 --> 00:21:00,220
So I'm actually going to go ahead and copy the values from my previous application.

258
00:21:00,290 --> 00:21:05,240
I'm going to say these are my objects so I have the same cities again.

259
00:21:05,240 --> 00:21:09,290
So I want to filter the same guys once they filter them.

260
00:21:09,290 --> 00:21:15,920
I want to reload the table view from the results view controller based on these filter values.

261
00:21:15,990 --> 00:21:22,400
Want to go ahead and say my results view controller dot array.

262
00:21:22,400 --> 00:21:28,880
I don't remember what they called the array results array that becomes the city's array unless filter

263
00:21:28,880 --> 00:21:33,920
is the filtering is going to happen exactly like what we did last time in the filter.

264
00:21:33,950 --> 00:21:35,990
I'm going to give it a string.

265
00:21:35,990 --> 00:21:43,490
I'm going to call it N3 which is after type a string and I'm going to go ahead and say return if entry

266
00:21:44,230 --> 00:21:47,950
dog contains what do I want to get from the contain.

267
00:21:47,960 --> 00:21:59,300
I want to get these search controller dot search bar dot text so essentially for any item in the city's

268
00:21:59,320 --> 00:22:03,690
array if they have any part of this search bar text within them.

269
00:22:03,790 --> 00:22:10,740
If they contain that return that has a true value and add them to the results array of their results

270
00:22:10,750 --> 00:22:11,940
controller.

271
00:22:11,950 --> 00:22:19,840
Now finally I have to say once that is done my results controller day table view died the reload your

272
00:22:19,840 --> 00:22:20,630
data.

273
00:22:20,770 --> 00:22:25,030
The last thing they have mentioned is present the results of your controller.

274
00:22:25,030 --> 00:22:26,850
But that happens automatically.

275
00:22:26,860 --> 00:22:33,550
The moment that the value in this area is not to nil which means the resource you control has something

276
00:22:33,550 --> 00:22:35,970
to show it will automatically appear.

277
00:22:35,980 --> 00:22:40,050
So we don't really need to worry about that but somebody gets rid of all of these comments.

278
00:22:40,600 --> 00:22:44,820
And now the only thing I should change in here and that's something we saw last time.

279
00:22:44,860 --> 00:22:50,130
Maybe I want to make it lower cased in here and also for the text I want to make it law.

280
00:22:50,170 --> 00:22:56,470
So essentially every combination of the characters would work against each other so empty lower case

281
00:22:56,740 --> 00:22:59,960
contains searched by text lawyer case.

282
00:23:00,700 --> 00:23:06,640
Now if you're on this application we should be able to see a search bar in our container view and if

283
00:23:06,640 --> 00:23:14,260
you search on it a new table view should appear somewhere going here and say an eye presents the ones

284
00:23:14,260 --> 00:23:17,950
that they have an end within them and I nothing.

285
00:23:18,010 --> 00:23:19,690
And e only one of them.

286
00:23:19,690 --> 00:23:20,940
So on and so forth.

287
00:23:20,980 --> 00:23:26,140
If we don't have any of them we obviously don't see anything about the table view simply because this

288
00:23:26,140 --> 00:23:28,220
view wasn't a table view.

289
00:23:28,240 --> 00:23:34,120
If I go back in here to my storyboard I could actually show you that here the background in here it

290
00:23:34,120 --> 00:23:35,790
could be essentially anything.

291
00:23:35,790 --> 00:23:43,660
You could have a maybe a text the text to a large text view that is in here and I'm actually going to

292
00:23:43,660 --> 00:23:51,390
set the constraints for it's all vertical spacing and leading training and the by the mass spacing and

293
00:23:51,420 --> 00:23:54,930
where they could do is I could make its make on color different.

294
00:23:55,030 --> 00:23:58,510
So this is a view controller that is doing its own thing.

295
00:23:58,810 --> 00:24:00,610
Maybe you have some information on it.

296
00:24:00,610 --> 00:24:06,040
Maybe you have a map on it or any other kind of object but then you also have a set of items that you

297
00:24:06,040 --> 00:24:08,350
want to be able to filter through them.

298
00:24:08,410 --> 00:24:10,610
So I could go in here and say new.

299
00:24:10,750 --> 00:24:15,220
And then if I get New York maybe you want to do something there's been a tap on that.

300
00:24:15,260 --> 00:24:21,420
That one essentially appears in here or anything of the sorts that you can simply imagine to do.

301
00:24:21,670 --> 00:24:28,360
So that was a quick introduction of how to use search within a table view or how to use search using

302
00:24:28,390 --> 00:24:35,740
a search controller which allows for both the search and results of your controller to be presented.

303
00:24:35,890 --> 00:24:38,860
Let's keep it up to here and I'm going to move on to our next lesson.
