Assignment #4 Task #5

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

Any list of photos should display the photo’s title as the table view cell’s title and its description as the table view cell’s subtitle. If the photo has no title, use its description as the title. If it has no title or description, use “Unknown” as the title.

Similar to task #3 we create two helper functions:

- (NSString *)titleOfPhoto:(NSDictionary *)photo
{
    NSString *title = [photo objectForKey:FLICKR_PHOTO_TITLE];
    if ([title length]) return title;
    title = [photo valueForKeyPath:FLICKR_PHOTO_DESCRIPTION];
    if ([title length]) return title;
    return UNKNOWN_PHOTO_TITLE;
}

- (NSString *)subtitleOfPhoto:(NSDictionary *)photo
{
    if ([[photo objectForKey:FLICKR_PHOTO_TITLE] length])
        return [photo valueForKeyPath:FLICKR_PHOTO_DESCRIPTION];
    return @"";
}

Please note that the access of the description works slightly different as it is stored in a kind of subset of the dictionary.

Finally we use those functions to populate the table cells:

    cell.textLabel.text = [self titleOfPhoto:photo];
    cell.detailTextLabel.text = [self subtitleOfPhoto:photo];

The complete code for this task is available at github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Leave a Reply

Your email address will not be published.