Removing Cars

You can add cars, but how do you delete them? It turns out that most of the code you need for simple deletion was created when you added the CarTableViewController class. To enable deletion, all you really need to do is uncomment and modify one of the provided methods.

Note that there is another related method, tableView:canEditRowAtIndexPath:, that allows you to optionally enable or disable editing for an individual cell. Although you do not use it in the CarValet app, you should know how to use it. Uncomment the method, and for now, have it return NO for any odd row.

There are many ways to do this. Perhaps the simplest is to use just one line with the modulo operation. Remember that the row index starts at 0, so line 1 has a row ...

Get Learning iOS Development: A Hands-on Guide to the Fundamentals of iOS Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.