title: How do I set Section-Header.xib constraints in UITableView programmatically using Objective-C
body: <p>I want to set the width constraints programmatically using Objective-C.</p>
  
  <p>The below code is working fine when I build my app using <strong><code>Xcode 7.2.</code></strong></p>
  
  <pre><code>  [secHeaderView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_sectionHeaderView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_sectionHeaderView)]];
  
      [secHeaderView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_sectionHeaderView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_sectionHeaderView)]];
  </code></pre>
  
  <p>Now when I run my app using <strong><code>Xcode 9.3</code></strong>, then my secHeaderView's are missing. It's due to the constraints which are mentioned above.</p>
  
  <p>If I comment out the above constraints, then I can see my secHeader View, but the width is not properly set. It shows 70% width of UIScreen.</p>
  
  <p>This is how my secHeaderView looks, but the width is not properly set...</p>
  
  <p><a href="https://i.stack.imgur.com/92AmI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/92AmI.png" alt="enter image description here"></a></p>
  
  <p>Here is my actual code:</p>
  
  <pre><code>- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
      _sectionHeaderView = [[NSBundle mainBundle] loadNibNamed:@"BasicProdInfoSectionHeaderView" owner:self options:nil].firstObject;
      SectionHeader *currentHeader = [self.titleStringArray objectAtIndex:section];
  
      [_sectionHeaderView setTitleWithText:currentHeader.titleLabel];
      _sectionHeaderView.expandableButton.tag = section;
  
      [_sectionHeaderView.expandableButton addTarget:self action:@selector(expandButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
      UIView *secHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,[[UIScreen mainScreen] bounds].size.width , 50)];
      _sectionHeaderView.translatesAutoresizingMaskIntoConstraints = NO;
  
      [secHeaderView addSubview:_sectionHeaderView];
      [secHeaderView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_sectionHeaderView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_sectionHeaderView)]];
      [secHeaderView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_sectionHeaderView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_sectionHeaderView)]];
  
      if (section != 3) {
          secHeaderView.layer.shadowOffset = CGSizeMake(0, 1);
          secHeaderView.layer.shadowRadius = 1;
          [secHeaderView.layer setShadowColor:[UIColor blackColor].CGColor];
          secHeaderView.layer.shadowOpacity = 0.25;
      }
  
      return secHeaderView;
  }
  </code></pre>