cs193p – Assignment #6 Extra Task #4

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

Make one or more of your table views searchable. Check out UISearchDisplayController and UISearchBar.

Add a bar button to enable the search functionality in code and initialize it lazily:

@property (nonatomic, strong) IBOutlet UIBarButtonItem *searchButton;
...
- (UIBarButtonItem *)searchButton
{
    if (!_searchButton) {
        _searchButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch
                                                                      target:self
                                                                      action:@selector(searchButtonPressed:)];
                         
    }
    return _searchButton;
}

- (void)viewDidLoad
{
    ...
    self.navigationItem.rightBarButtonItem = self.searchButton;
}

Continue reading “cs193p – Assignment #6 Extra Task #4”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Extra Task #3

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

Have a row in your main table view called “All” which shows all the photos (not just the photos with a certain tag). Then have the table that appears when you click on “All” be divided into sections by tag (i.e., each section is one of the tags). The simplest way to add the “All” row is to update the information in your database a little bit rather than trying to special-case your table view code (though you will need a special case to turn on sections for that particular table of all photos since you don’t want other tables of photos to have sections). Luckily “All” is alphabetically at the top of the list of types of places, but can you think of a way to modify your schema/fetch criteria to ensure that it is always the top item in the list even if it’s not called “All” or if there were an “Abattoir” tag in the list?

Just add an additional tag for “All” to all photos. To circumvent to “Abattoir” sorting problem, name it so that it will be always be first, e.g.:

#define ALL_TAGS_STRING @"00000"
...
+ (NSSet *)tagsFromFlickrInfo:(NSDictionary *)photoDictionary
       inManagedObjectContext:(NSManagedObjectContext *)context
{
    ...
    tagStrings = [tagStrings arrayByAddingObject:ALL_TAGS_STRING];
    ...
}

Continue reading “cs193p – Assignment #6 Extra Task #3”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Extra Task #2

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

Allow users to delete photos (i.e. they no longer appear in tables). You should do it in a way that makes it so that the UIRefreshControl does not bring them back!

Deleting of cells is enabled by providing the appropriate delegate method. There delete the current photo and save the core-data document:

-  (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
 forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        Photo *photo = [self.fetchedResultsController objectAtIndexPath:indexPath];
        [photo.managedObjectContext performBlock:^{
            [photo delete];
            [[SharedDocumentHandler sharedDocumentHandler] saveDocument];
        }];
    }
}

Continue reading “cs193p – Assignment #6 Extra Task #2”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Extra Task #1

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

Divide all tables of photos (except maybe the “All” table below) into alphabetical sections. This turns out to be easy in table views driven by Core Data, but only if you have an attribute in the database which is “that photo’s section heading” and which sorts in exactly the same order as the photos themselves sort.

Add another attribute to the Photo entity to hold the first letter of each photo title. Recreate its sub class and adjust its category:

+ (Photo *)photoWithFlickrInfo:(NSDictionary *)photoDictionary
        inManagedObjectContext:(NSManagedObjectContext *)context
{
        ...
        photo.firstLetter = [photo.title substringToIndex:1];
        ...
}

Continue reading “cs193p – Assignment #6 Extra Task #1”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Task #7

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

Your application must continue to work properly in portrait and landscape and on iPhone 4, iPhone 5 and iPad. It must also verify that it continues to work properly on a physical device (of your choice).

… already done …

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Task #6

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

When the user refreshes the table view (with the UIRefreshControl), you should refetch the data from Flickr in a thread and update your Core Data database and then update the UI to show any new data. This refresh should automatically invoke upon launch of your application if the Core Data database is empty.

Currently a download starts every time the app launches. Remove the access to Flickr from viewDidLoad and adjust viewWillAppear: to start the download only, when core data is empty:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (!self.sh.managedObjectContext)
        [self.sh useDocumentWithOperation:^(BOOL success) {
        [self setupFetchedResultsController];
        if (![self.fetchedResultsController.fetchedObjects count])
            [self loadPhotosFromFlickr];
    }];
}

The complete code is available on github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Task #5

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

This week’s version should still never block the main thread with any Flickr fetches and should continue to cache photo (non-thumbnail) image data in the file system in the same way as last week’s assignment.

… already done …

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail