Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Now that we can add feeds, we should be able to delete feeds, too. Cocoa Touch has a neat UI for this. You can press an Edit button which will reveal special red delete icons, or you can swipe to delete. This interface is easy to implement, and because it's so common, it will be familiar to the user. So, we'll start by making a working copy of BWRSS-addView-05, and we'll rename it as 06. So, I'm going to use the done version here. And you can use the done version or you can use the version that you created in the last movie if you've been following along.
And I'm going to open this in Xcode by double-clicking on the Xcode project file. And we're going to come back out here to the Finder and I'm going to open this 06-methods.txt file. And it just has this one method in it, and I'm going to copy that and come over in to Xcode and we'll paste it in. We're going to put this right at the end of the tableView section. We'll go ahead and delete all of this, and we'll just paste it in right there.
This method is called tableView commitEditingStyle forRowAtIndexPath, and it passes this editingStyle, and if the editingStyle is the ViewCellEditingStyleDelete, then we go ahead and implement the delete. So, this is really very simple, and if we go ahead and run this in the iPhone Simulator, we see we have the CNN.com Top Stories that we added in the last movie. I'm just going to press this Edit button and you'll notice there I get these little red Delete icons. If I select the one next to CNN.com Top Stories, I get a Delete button, and I can press that, and it deletes it, and I can press Done, and it's gone. And that's all what we've just implemented here.
It actually deleted it from the database and it loaded the FeedIDs again and displayed them again, and it calls this deleteRowsAtIndexPath with RowAnimation to animate the delete, and we're using this fade method. We can change this, and there's a number of different methods available. We could use one called Left. I need to stop it and run it again. And I'll go ahead and I'll add CNN again, and then we delete it. We will go ahead and this time we'll do the swipe gesture for delete, and when we do the swipe gesture, we get the same little Delete button, and you'll notice this time it's swiped off to the left for the delete.
So, we have left, we have right, we have top, we have middle, and we have automatic, as well as the fade that we started with. The middle one is a little bit interesting. It might not show up well on the screen, but if you try this on your computer-- I'm going to go ahead and run this again, and we'll add that same feed again, and we'll go ahead and delete it-- you see that it folds over when I press this, and it deletes it that way. So, I'm just going to return this to the fade version, and we'll save that I'm going to press Command+.
to stop it running on the simulator. So, that's really all there is to it. Cocoa Touch makes this really easy to implement and all the heavy lifting is done for you. All you need to do is implement the proper delegate method, and it works just fine.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101314 Viewers
61 Video lessons · 88071 Viewers
71 Video lessons · 71925 Viewers
56 Video lessons · 103750 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.