Sort the Table

One of the features of MyContactList is to be able to sort the table by different criteria as specified on the Settings screen. The code changes to enable sorting are relatively minor because the Core Data framework handles the heavy lifting. You need to import Constants.h and then make changes to loadDataFromDatabase: in LMAContactsTableController.m, as shown in Listing 12.13.

Listing 12.13 Enable Sorting of the Table

- (void) loadDataFromDatabase{    //read settings to enable sorting    NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];           //1    NSString *sortField = [settings stringForKey:kSortField];                   //2    bool sortAscending = [settings boolForKey:kSortDirectionAscending ...

Get Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android 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.