dzenbot / DZNEmptyDataSet

A drop-in UITableView/UICollectionView superclass category for showing empty datasets whenever the view has no content to display
https://www.cocoacontrols.com/controls/dznemptydataset
MIT License
12.09k stars 1.73k forks source link

Activity Indicator and EmptyDataset #301

Open SeanMurphy15 opened 7 years ago

SeanMurphy15 commented 7 years ago

Hey ya'll!

Currently, my problem is that the EmptyDataset view appears while my tableview is fetching data. Then it disappears while the tableview gets data. Ideally, I'd like an activity indicator to appear while the data is being fetched and to have the EmptyDataset view appear only if there's no data to present.

I could use GCD with a time interval to give my tableview time to load data while presenting the activity indicator view. However, I feel that's kind of hacky. Is there a delegate method that I'm missing? Thanks in advance!

bartvandendriessche commented 7 years ago

You can override customViewForEmptyDataSet: and return a UIActivityIndicatorView while your controller is fetching data.

- (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView {
    if (self.isLoading) {
        UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        [indicator startAnimating];
        return indicator;
    }
    return nil;
}
SeanMurphy15 commented 7 years ago

Awesome! That works! However, when I have an empty array for my tableview the indicator spins forever.

What's the best way to disable the custom UIActivityIndicatorView and display my EmptyDataSet when there is no data?

bartvandendriessche commented 7 years ago

Not sure what you mean, you can just make sure isLoading is false and reload your tableView with the empty array.

Any time customViewForEmptyDataSet: returns nil, the standard empty state will be shown.

SeanMurphy15 commented 7 years ago

Ok, I'm coding in Swift. Is there an equivalent to isLoading?

bartvandendriessche commented 7 years ago

You have to implement isLoading yourself regardless if you use Swift or Objc.

It may be better to post a question on StackOverflow if you can't get this to work, because this isn't an issue with DZNEmptyDataSet.

SeanMurphy15 commented 7 years ago

Good call. Thanks for the help @bartvandendriessche !

parinshah30 commented 7 years ago

@bartvandendriessche what is a good place to implement isLoading?