Please note, this blog entry is from a previous course. You might want to check out the current one.
Show your lists sorted alphabetically. There are two methods that might be helpful in this: sortedArrayUsingSelector: and sortedArrayUsingDescriptors:. The former is good when you have an array of NSString objects. The latter is good when you have an array of NSDictionary objects (and you want to sort by one of the values in the dictionaries).
… actually use both! The first one to sort the tags:
- (NSString *)tagForRow:(NSUInteger)row { return [[self.photosByTag allKeys] sortedArrayUsingSelector:@selector(compare:)][row]; }
The second one to sort the photos by name:
- (void)setPhotos:(NSArray *)photos { _photos = [photos sortedArrayUsingDescriptors:@[[[NSSortDescriptor alloc] initWithKey:FLICKR_PHOTO_TITLE ascending:YES]]]; [self.tableView reloadData]; }
The complete code is available on github.