cs193p – Assignment #5 Task #6

Please note, this blog entry is from a previous course. You might want to check out the current one.

Sort all tables alphabetically (and case insensitively) except the Recents table (which should still be sorted with the most recently viewed first). A good solution to this might involve some of the array sorting methods that use blocks.

… actually the code up to this task already does sorting, but now it will be implemented using blocks.

For the tags create a new property – to do not have to resort everything every time the table needs to display a row:

@property (nonatomic, strong) NSArray *tags;
...
- (void)updatePhotosByTag
{
    ...
    self.tags = [[photosByTag allKeys] sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
        return [obj1 compare:obj2 options:NSCaseInsensitiveSearch];
    }];
}


… and use this new property in the rest of the code:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
                ...
                    NSString *tag = self.tags[indexPath.row];
                    ...
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.tags count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ...
    NSString *tag = self.tags[indexPath.row];
    ...
}

The photos can be sorted analogue (this time using its title):

- (void)setPhotos:(NSArray *)photos
{
    _photos = [photos sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
        return [obj1[FLICKR_PHOTO_TITLE] compare:obj2[FLICKR_PHOTO_TITLE]
                                         options:NSCaseInsensitiveSearch];
    }];
    [self.tableView reloadData];
}

The complete code is available on github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

3 thoughts on “cs193p – Assignment #5 Task #6”

  1. i’m reading your code about A5, and i’m wondering why there is no mapkit part. and i have some problems about setting region of map connect with photo annotations.

      1. Thank you!! i’m still working on the last year assignment ~ Great thanks, and i learn a lot in your code.

Leave a Reply

Your email address will not be published.