Deleting Records

If you’ve been running the app to test it along the way, you probably have a long list of contacts that cannot be deleted. This is not an ideal situation, so now it’s time to add the capability to delete records from both the table and the database.

The pattern here is slightly different from what you did to be able to add records. You still need to create a button for the navigation bar that will put the table in edit mode. In edit mode, the user can tap a row to delete it from both the table and data source. This requires implementing a UITableViewDataSource delegate method that is called when the user selects a row for deletion.

Start by adding this line to the end of viewDidLoad: in LMAContactsTableController.m:

Get Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.