soffes / ssdatakit

Eliminate your Core Data boilerplate code
MIT License
453 stars 57 forks source link

Reload the table view the first time it is shown. #23

Closed calebd closed 10 years ago

calebd commented 10 years ago

Reload the table view the first time it is shown. This is how UITableViewController works afiak.

soffes commented 10 years ago

Is there a way to do this without using the ivar?

kylef commented 10 years ago

I do something similar to this in my own table view data source. I make sure the table view is reloaded when we perform the fetch request.

I think something like the following could be cleaner (and prevents using an ivar).

- (BOOL)performFetch:(NSError **)error {
    BOOL result = [[self fetchedResultsController] performFetch:error];
    [[self tableView] reloadData];
    return result;
}

When the fetch request is set, I would then perform the fetch.

- (void)setFetchedResultsController:(NSFetchedResultsController *)fetchedResultsController {
    _fetchedResultsController = fetchedResultsController;
    [self performFetch:nil];
}

I don't think there is a need to perform a reload on viewWillAppear:. Instead just make sure the table view is updated when the fetch happens (if it happens after the table view is loaded).

calebd commented 10 years ago

What do you think @soffes @kylef?

soffes commented 10 years ago

You should probably add the same thing to the collection view variant too.

soffes commented 10 years ago

My bad on closing. Silly GitHub.

calebd commented 10 years ago

Bump.