2
  1. I have Created Two UIView one headerview and second is UICollectionView both subview of UIScrollView and I have hidden my NavigationBar entire app.

  2. Now I have added below code for set "SafeAreaLayoutGuides" in iOS11 but here application crass due to superview nil found.

I have added below code.

    UIView *parentView = self.view.superview;
    UIView *childView = scrollViewMain.superview;
    childView.translatesAutoresizingMaskIntoConstraints = NO;

    NSLayoutConstraint *topConstraint;
    NSLayoutConstraint *bottomConstraint;

    if (@available(iOS 11, *)) {
        topConstraint   = [NSLayoutConstraint constraintWithItem:childView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:parentView.safeAreaLayoutGuide attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];

        bottomConstraint   = [NSLayoutConstraint constraintWithItem:childView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:parentView.safeAreaLayoutGuide attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
    } else {
        topConstraint   = [NSLayoutConstraint constraintWithItem:childView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:parentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];

        bottomConstraint = [NSLayoutConstraint constraintWithItem:childView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:parentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
    }

    [parentView addConstraint:topConstraint];
    [parentView addConstraint:bottomConstraint];
Jack
  • 13,571
  • 6
  • 76
  • 98
jeetendra_coder
  • 269
  • 3
  • 13

1 Answers1

1

If parentView is nil (because self.view.superview is nil), then that means that self.view hasn't been added to the view hierarchy yet.

Make sure that whatever view contains this one has called self.addSubview(childView); that'll fix the "nil superview" issue.

bryanjclark
  • 6,247
  • 2
  • 35
  • 68