Welcome back again.
This lesson is going to be a very simple lesson we learn how to use a pull refresh control to refresh
the content of a table view.
So I'm going to school in here.
I'm going to add a new application.
I'm going to call it table view.
I think that table view refresh control.
And again we have to do the basic stuff what I'm going to try to do them as quickly as they can in their
storyboard.
I don't have this file.
Instead I have an actual table view controller.
My table view controller has a cell that has an I.D. called Cell I.D..
It is basic.
This is the initial view controller and I do have a class for it called my table view controller which
in this storyboard is connected to here is all the things that we have done so many times so far and
I'm trying to get through them as quickly as I can.
And I have a valuable called my array which has only two cities in it Vancouver and New York and then
in the number of the rows I have my array count.
These are the only thing that matter in this particular application.
And then I also have a cell for row that uses the cell a D doesn't need the index part because I'm not
really using that for anything.
I'm trying to cut down on the amount of code and come up with the simplest possible stuff and then they
have to do in here is this I have to say cell that fixed table dot text becomes my array object that
index part DOT rule and that's all I have to do to just show some stuff in my table view.
Now this is something that we have done so many times before then new we want to happen in here is we
want to be able to pull our people view using a UI refresh control and refresh the content of the table
view.
So to do that I'm going to go ahead and say I have a value event called My refresh control which is
of the type you I refresh control and then of course I have to initialize it in my view did load.
So in my view that Lord I'm going to go ahead and say My refresh control is a you I refresh control
and then my refresh control essentially has to do something when it gets pulled.
So we have to essentially add a target for it and I'm going to say add the target on the target for
it is this I'm gonna go ahead and say at Target within self and the action for it is selector let's
find an action for it I'm going to add something for it call it function refresh function and then it
is called fine Shen then it is called is gonna call that one for the White event obviously that value
changed value changed so when the refresh controller gets pulled it has to essentially call this one
now I still have to do two things.
One of them is to get rid of the error I have to say this is an art objective c kind of function so
it exposes the selector and the other thing is we have made the refresh control but we haven't really
added this to anyone and for that I'm going to go ahead and say self dot table view dot the sub view
and I'm going to add the refresh control as a sub view to my table view to my table view will have that
rotating you know bar that shows our study is being refreshed at the time the last thing that we're
doing here before I can do an actual test with new data is once we come to the refresh control and we
deal with the refresh or whatever we're trying to do when I'm going to do in here is it say self doubt
table view data reload the data and then also my refresh control we have to and refreshing.
So let's go ahead and run this application.
He doesn't really do anything right now but he's gonna show us visually how refresh control works once
we know that we can actually add extra data to our table view array as well so we now have this table
view and if we pull it we can see the refresh happening up there it doesn't stay there for a very long
time but it shows us that it is refreshing itself now the refresh usually happens when you are trying
to pull new information from a network or somewhere.
So because of that I'm going to actually try to simulate that even though this isn't a very good way
of doing it but I'm going to say my array not append lets up and the few new cities to say I have a
new city this one and I'm going to have another one.
Let's say that is going to be real and then I'm going to go ahead and say even let's let's talk details
about this I'm going to say my array dot sort them as well.
So by now then the refresh happens some new information appears.
Like I said this is a process that usually happens through a network and you will have to wait for the
network to finish its work using a completion block and victim the completion block.
We often actually run the table view reload and refresh control if we wait for those to happen.
We will see more of these when we talk about networking in a few sections from now.
But for now every time that we refresh it has to add the two new cities sort everything reload table
view and end the refresh.
Let's see that.
Yes.
And once again it does the same thing obviously it keeps adding new Delhi and Rio because every time
it comes in here and appends to them it doesn't know that they already exist in there.
So that's a very simple refresh contour for a table view used primarily when your data changes depending
on a network status.
Let's keep it up to here and we'll move on to our next lesson.