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

Empty data set view is not vertically aligned correctly #371

Open movesmyers opened 6 years ago

movesmyers commented 6 years ago

I am using DZNEmptyDataSet on UITableViews and UICollectionViews throughout my application running iOS 11.1. These are designed in storyboards and don't have any constraints set in the storyboard or in code. All of the empty data set views are aligned very far down in the view, almost at the bottom. The strange thing is that if I add an item to the tableview or collectionview, and then remove the item, the empty set view will be aligned correctly.

I can't set the vertical offset in code, as even though it will be aligned correctly at first, once an item is added and removed, the empty data set view will once be aligned incorrectly,

Following is my configuration. self.collectionView.emptyDataSetSource and self.collectionView.emptyDataSetDelegate are set in viewDidLoad.

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {

  NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:24.0f],
                               NSForegroundColorAttributeName:[UIColor grayColor]};

  return [[NSAttributedString alloc] initWithString:@"(redacted)"
                                         attributes:attributes];
}

- (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView {

  NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
  paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  paragraph.alignment = NSTextAlignmentCenter;

  NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0f],
                               NSForegroundColorAttributeName:[UIColor grayColor],
                               NSParagraphStyleAttributeName:paragraph};
  NSString *text = @"(redacted)";

  return [[NSAttributedString alloc] initWithString:text
                                         attributes:attributes];
}

- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  return [UIImage imageNamed:@"(redacted)"];
}

Is there anything else I should include?

Thank you for any help anyone can provide!

Dysonapps commented 6 years ago

I’m seeing this too, very annoying. My first reaction is that DZNEmptyDataSet is conflicting with iOS 11’s safe area and the issue presents itself when you migrate a VC’s storyboard to using safe areas.

On Nov 26, 2017, at 12:03 AM, Richard Myers notifications@github.com wrote:

I am using DZNEmptyDataSet on UITableViews and UICollectionViews throughout my application. These are designed in storyboards and don't have any constraints set in the storyboard or in code. All of the empty data set views are placed very far down in the view, almost at the bottom. The strange thing is that if I add an item to the tableview or collectionview, and then remove the item, the empty set view will be aligned correctly.

I can't set the vertical offset in code, as even though it will be aligned correctly at first, once an item is added and removed, the empty data set view will once be aligned incorrectly,

Following is my configuration. self.collectionView.emptyDataSetSource and self.collectionView.emptyDataSetDelegate are set in viewDidLoad.

  • (NSAttributedString )titleForEmptyDataSet:(UIScrollView )scrollView {

    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:24.0f], NSForegroundColorAttributeName:[UIColor grayColor]};

    return [[NSAttributedString alloc] initWithString:@"(redacted)" attributes:attributes]; }

  • (NSAttributedString )descriptionForEmptyDataSet:(UIScrollView )scrollView {

    NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new]; paragraph.lineBreakMode = NSLineBreakByWordWrapping; paragraph.alignment = NSTextAlignmentCenter;

    NSDictionary attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0f], NSForegroundColorAttributeName:[UIColor grayColor], NSParagraphStyleAttributeName:paragraph}; NSString text = @"(redacted)";

    return [[NSAttributedString alloc] initWithString:text attributes:attributes]; }

  • (UIImage )imageForEmptyDataSet:(UIScrollView )scrollView { return [UIImage imageNamed:@"(redacted)"]; } — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/dzenbot/DZNEmptyDataSet/issues/371, or mute the thread https://github.com/notifications/unsubscribe-auth/AA_UB_50_EVqC1Zk3VO14UsdI9lTQJfDks5s6PEhgaJpZM4QqqQU.

movesmyers commented 6 years ago

I am definitely using Safe Areas, so that might indeed be the problem. I am confused, however, about why it would work once an item is in the table or collection view and is then deleted. Are you seeing that too, @Dysonapps ?

Dysonapps commented 6 years ago

Seeing exactly the same. The docs say something about safe area guides being non-0 only after views are loaded so layout is possibly being done too early in the view lifecycle?

This library definitely doesn’t seem to be safe area ready.

movesmyers commented 6 years ago

I just made my own simple empty set view that I set manually. Hopefully this repo can be taken over at some point and actively maintained, it was awesome!

dispatchswift commented 6 years ago

I'm having the same issue. Any suggestions on how to fix vertical alignment?