Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

EmptyDataSet view disappears on reloadData #86

Open
zentraedi opened this issue Jun 26, 2015 · 15 comments
Open

EmptyDataSet view disappears on reloadData #86

zentraedi opened this issue Jun 26, 2015 · 15 comments

Comments

@zentraedi
Copy link

Hi!

I'm integrating DZNEmptyDataSet in my project and falls into place. However, i have a method that fetches the data for the tableview from the backend and as soon as i call reloadData, the table view shows the prototype cell i have defined.

This is the code:

[self fetchTransactionsOnCompletion:^(BOOL success) {
        if (success) {
            [self.overallTransactionsAmount setText:[NSString stringWithFormat:@"$%0.2f", [_transactions overallAmount]]];
            [self.tableView reloadData];
            [HUD hide:YES];
        }else{
            [alert show];
        }
    }];

If i don't call reloadData the DZNEmptyDataSet view shows just fine. If i call reloadData, be it in viewDidLoad, viewWillAppear or pull down refresher, it just goes away.

Am i missing something?

Thanks in advance...

@dzenbot
Copy link
Owner

dzenbot commented Jun 28, 2015

Have you tried this?

@zentraedi
Copy link
Author

Actually yes, but then it shows an empty view.

Any idea what can be happening?

Thanks again.

@dzenbot
Copy link
Owner

dzenbot commented Jun 29, 2015

It's hard to tell without seeing any of your implementation.
Please publish a gist of your view controller implementation.

@zentraedi
Copy link
Author

Sure.

-(void)viewDidLoad
{
    [super viewDidLoad];

    self.tableView.emptyDataSetSource = self;
    self.tableView.emptyDataSetDelegate = self;

    refreshControl = [[UIRefreshControl alloc]init];
    [self.tableView addSubview:refreshControl];
    [refreshControl addTarget:self action:@selector(refreshTable) forControlEvents:UIControlEventValueChanged];

    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    alert = [[UIAlertView alloc] initWithTitle:@"Error fetching data" message:@"Please try again." delegate:self cancelButtonTitle:nil otherButtonTitles:@"Got it!", nil];

    [self showSimpleHUDWithLabel:@"Fetching transactions..."];
    [self fetchTransactionsOnCompletion:^(BOOL success) {
        if (success) {
            [self.overallTransactionsAmount setText:[NSString stringWithFormat:@"$%0.2f", [_transactions overallAmount]]];
            [self.tableView reloadEmptyDataSet];
            [HUD hide:YES];
        }else{
            [alert show];
        }
    }];

}

I have an UIView above the table and i'm not sure if that's causing the issue.

screen shot 2015-06-29 at 12 05 01 pm

Thanks again!

@dzenbot
Copy link
Owner

dzenbot commented Aug 4, 2015

By implementation, I meant the DZNEmptyDataSetSource and DZNEmptyDataSetDelegate implementations.

@z0527z
Copy link

z0527z commented Aug 10, 2015

I also have the same problem in the condition of calling [tableView reloadData] the second time to show the empty view. I do this for paging demand.
When I find this,I debug it in view hierarchy and find the empty view added to tableView, but its position not correct. It lays far away below the edge of screen bottom.

To fix this, I change the following code. in function:

 void dzn_original_implementation(id self, SEL _cmd)

I exchanged the order of

[self dzn_reloadEmptyDataSet]; `

and

 if (impPointer) {
        ((void(*)(id,SEL))impPointer)(self,_cmd);
    }

That seems to solve the problem.
What I want to know is, did this change will cause some problem?
What is the original purpose of putting the original implementation after the injection?
What I know is, we often put our implementation after original or super implementation.

Thanks in advance...

@dzenbot
Copy link
Owner

dzenbot commented Aug 10, 2015

What version of the library are you using? In wich OS and devices does this happen?

@zentraedi
Copy link
Author

Last version fixed issues for me!

Thanks.

@dzenbot
Copy link
Owner

dzenbot commented Aug 10, 2015

Great, thanks for the heads up @zentraedi!
@z0527z did you try latest version?

@z0527z
Copy link

z0527z commented Aug 11, 2015

of course its the latest 1.7 version, I update yesterday before I find the problem @dzenbot

@dzenbot
Copy link
Owner

dzenbot commented Aug 11, 2015

@zentraedi reported the latest version fixed the issue for him, that why I asked.

@jhson114
Copy link

jhson114 commented Oct 8, 2015

@dzenbot Hi, I ran into same issue. When reloadData is called after tableView has scrolled, the scrollView's contentSize does not reset by the time dzn_reloadEmptyDataSet is called. Therefore DZNEmptyDataSetView's frame.y is placed at the scrollView's last contentOffset. Switching the injection order as mentioned by @z0527z did fix the issue. Another fix was to reset the scrollView's contentSize in dzn_reloadEmptyDataSet. I'm using the latest version.

@rubenadlm
Copy link

I have the same problem when reloadData after tableView has scrolled.

@dzenbot
Copy link
Owner

dzenbot commented May 28, 2016

I believe #182 should fix this issue.

@magnett
Copy link

magnett commented Aug 26, 2016

I had it too with a collectionView. A quick & dirty fix is to call [self.collectionView setContentOffset:CGPointZero animated:NO]; right before the reload data.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants