Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
  • Overview
  • Transcript

4.1 Presenting the Feeds

Now that we've done all the heavy lifting as far as downloading and parsing the data, let's actually get something up on the screen. So what we're going to do now, now that we have at least started populating the feeds array here, now we can start to put some data in there. And then, as we started to introduce earlier, we have these, this implementation here of a table view data source that comes from the fact that this is a subclass of a UI table view controller. So, we're going to start to tap into this now. So, I started to introduce this a little bit earlier. So, we have three different functions here. We have the number of sections in a table view. So, since we're dealing with the feeds still and really, throughout this course, we're not worried about creating different sections in our table view controller. So, all we're gonna do is return one. We're just gonna hard code one, there's one section, end of story. Now, we have this whole number of rows in section, so in here, we need to know how many rows that need to be presented to the user within this table view. Now, we can't really hard code this, because we're never gonna know, it's always, always going to be based on how much data is available. So what we're doing here up above, and all of these methods here for our NS XML parser delegate, is we're populating this feeds array. So what we need to know is how many different objects are inside that array currently. That's quite simple. We simply use the count properties, so there you go. Now we know, we're telling this particular method, that there are going to be however many feeds are in that array, are how many rows that are gonna be in this one section. Pretty simple, so now is where the interesting part comes into play. So now, we need to implement this final cell for row at index path function. Now this is where we're actually going to start to populate data within the actual cell or row within that table view. Now, if you recall, if we come back to our story board, we're talking about this particular guy right here. So this particular cell we wanna be able to populate, so if we zoom in a bit back to 100%. What we want to do is we want to populate this particular cell here with the data from our feed, and in this case all we want to do is put the title in there, that's all we really want to put in there. But, in order for this to work, we need to be able to reference a particular cell, or type of cell within this table view. And the way that we do that is through an identifier. So we're gonna specify an identifier here. We need to give this a name. We're just gonna keep this relatively simple. We'll call this a FeedCell, that's all it really is. So now we can get a reference to a feed cell, and then populate it with some data. Now that we have this identifier set, we can now reference all the different types or several different cell within this controller within this table view as this particular type of cell with that, with that particular identifier. So we can head back over to our table view controller for our feeds. And we can come down into here and actually play around with the implementation. So the first thing it does, which is pretty common throughout all these different table view controllers that you're gonna work with, is it needs to get a cell. So reference is a property that you get, simply because you are, a subclass of a UI table view controller. You get to use this property called table view, and you get to, a special method on there called d q, reusable cell with identifier. And in our case, we want to use the feed cell identifier that we specified, within the storyboard. Then it's gonna say, for index path. Now index path is gonna become a common concept, as well, as this is how you reference which particular, or the, the index at which particular cell is being selected, or that you're, that you're looking at with this block of code. So in this case, re-using this index path that's being passed into us for this cell for row at index path function and then it's being cast as a UI table view cell. So at this point, we have access to our cell and we can start to set different things on it. Now if you recall from our storyboard, all we really wanna put is our title on there, that's all we really care about. So to do that we're gonna need to know at what index we're at currently within our feeds collection, we're going to do that with the index path. So we're going to get rid of this, configure this cell comment here and we're gonna create a constant because we're only gonna be dealing with one feed that's not gonna change. This feed is gonna be a feed model and it's gonna be set to. We have a feeds collection that we created in a previous lesson so we have all the different feeds that we've been accumulating throughout this process. And then we're gonna reference a particular one within that array via our index path that we've been passed in and we have a property on there called row. Now, that's going to allow us to get the feed at this particular index. So, we can start from zero and go all the way through up to the number of feeds that are found within a particular array. So now we have the appropriate feed. Now, all we have to do is set some information on our cell. And, all we really care about, all we've set it up to do is have a single text label. So, we will say text label.text. It's going to be equal to our feed.title. Now this is going to yell at us a little bit for a similar reason as we've seen before so we have a little exclamation point here and it's saying UI table view and optional UI table view doesn't have a member named text. That's because this particular property here, this text label is once again an optional, so to get access to it as if it were just a UI label as opposed to an optional, we need to use the exclamation point. So that will let us go through. Now if we save and build this. And we cross our fingers and hope that everything is done correctly. We'll go ahead and hit run to actually fire this up within the simulator. And after it starts to run and load, you'll see here that we have now parsed out the title that we found within the Apple developer RSS feed we can kind of go verify this. If we come down here and take a look here's that channel that we talked about before. Here's the channel element and if we come down here look for title that we parsed out here surely enough news and updates. Apple developer. So now we've gotten to this point, but that's as far as we've gone. We've gotten a little boring to this point, we want to be able to click on this and actually get our data over here. As of right now we don't have it wired up to work quite that way all we're doing is saying all right, if I click on this show the articles. But we need, we need to actually show the articles and not just this empty list. So that's what we're gonna do in the next lesson

Back to the top