DZNEmptyDataSet icon indicating copy to clipboard operation
DZNEmptyDataSet copied to clipboard

Empty data set view is not vertically aligned correctly

Open movesmyers opened this issue 8 years ago • 5 comments

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!

movesmyers avatar Nov 26 '17 05:11 movesmyers

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 [email protected] 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.

Dysonapps avatar Nov 26 '17 05:11 Dysonapps

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 ?

movesmyers avatar Dec 09 '17 22:12 movesmyers

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.

Dysonapps avatar Dec 09 '17 22:12 Dysonapps

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!

movesmyers avatar Dec 14 '17 15:12 movesmyers

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

dispatchswift avatar Sep 27 '18 21:09 dispatchswift