Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Now that we're parsing the feed header, we need to send data back to the FeedsTableViewController for processing. Remember, the AddViewController object is a modal dialog. What we want to do is little processing as possible there. We created a small delegate protocol for communicating with the FeedsTableViewController, and now we're going to use it. So, let's start by making a working copy of addView-04, and I'm going to use my -done version. You can use the one that you worked on in the last movie if you like, if you've been following along. And I'm just going to call this addView-05, and I'm going to open it in Xcode by double-clicking on the Xcode project file.
Now, if we notice in our addView.h file, we have this protocol that we define, this RSSAddViewControllerDelegate protocol. And it has three methods in it, and those methods are actually going to be run in the FeedsTableViewController. So, the FeedsTableViewController is going to be the delegate for this delegate protocol. And you'll notice right here we have this property which is called delegate, which is of type id with this delegate protocol. And you'll notice, back here in our haveFeed method, we actually call haveAddViewRecord, which is one of our delegate methods, haveAddViewRecord on that delegate.
So, I'm going to uncomment this, and I'm going to uncomment this to dismiss the view controller. And now we need to set this delegate property here, and that gets set from the FeedsTableViewController. Now, in the FeedsTableViewController, this is going to be a set in our segue, because our segue is what happens when we press on that Plus button. Then we get the segue to the AddViewModelController and the model controller, it slides up the screen with that animation. It covers the entire screen. And before we can start handling this in the segue, we need to know about it, so we're going to come in here to our controller.h, and I'm going to import our AddViewController header. And I'm going to come down here to our interface which defines the class type and the parent class type.
I'm going to declare this protocol type as well. So, this is our RSSAddViewControllerDelegate. So, I'll save here, and I'm going to come back over here to the end file, and now we can handle this other segue. Now, if you remember, we come over here to the iPhone storyboard--and I'm just going to display this right side real quick. So, this is the segue here, and it has the segue identifier, SegueToAddView, so I'm just going to copy that so that I can paste it in and know that I have spelled it correctly.
Over here, I'm going to say else if (segue. identifier isEqualToString:@"SegueToAddView"), and then I'm going to declare a pointer to the BWRSS AddViewController class. And that's our destinationViewController in the segue, so I can just say destinationViewController. Now that we have a pointer to that destinationViewController, I can set its delegate to this FeedsTableViewController.
Now, when the AddViewController calls something on its delegate, it's going to be calling it on this controller, the BWRSS FeedsTableViewController. This controller is declared to handle that protocol. You notice up here it says that our protocol is not implemented yet. That's because we haven't yet added those methods. And so I'm going to add those methods right here before the database methods. And we'll come out here to the Finder, and we'll open our 05-methods.txt file, and there they are. I'm going to select all and copy and come back into Xcode and paste them in right there. Command+S to save.
So now, our AddViewController, when it has a feed, it's going to call this haveAddViewRecord with the feedRecord. Here in our FeedsTableViewController, here it is, and it's going to get that record, it's going to sign it to this new feed variable. And so we need to do one more thing. When that gets assigned, we need to come back up here in our view stuff, and I'm going to come down here and I'm going to declare a viewDidAppear, and if (newFeed), (self loadNewFeed).
If we come down here and we see what loadNewFeed does, it goes ahead and either inserts it in the database or updates it in the database, and it does this nice animation reveal. We'll see what that looks like right now. We're going to go ahead and run this in the simulator. So now, let's go ahead and add that CNN feed-- CNN.com--and I'll press Add, and you see it has that nice little horizontal reveal. You notice it's using this UITableViewRowAnimationLeft, and it's using the same one here when it's updated.
So, if I go ahead and put in that same URL, you'll notice that it comes in here and it just rotates it into place like that. So, if we come back up here to our AddViewControllerDelegate method, you'll notice here that there is URL errors and there is RSS errors. So, if I come back here to the simulator-- and let's just put in something that doesn't have a feed, like for instance music.bw.org I know that one doesn't have a feed--and it says, RSS Error did not find a feed.
So, that's this haveAddViewRecord message. And for an error, if I put in a URL that just doesn't exist, like x.y, and click Add, it says, URL Error, a server with a specified host name could not be found. So, those are these two messages here. So now the feed is being properly added and updated, and it's all working quite well. The delegate protocol that we created is very easy to use, and it's also working well. This allows the modal view to do its job while passing its results back to the main view so that it can do its job. It's all very neat and tidy.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97511 Viewers
61 Video lessons · 84750 Viewers
71 Video lessons · 68928 Viewers
56 Video lessons · 101379 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.