title: my UITableViewCell setting button
body: <p>I'm having trouble adding  button to my <code>UITableViewCell</code>, the cell has two <code>UILabel</code>s and two <code>UIImageView</code>s, sometimes the <code>UIImageView</code> will contain an image and sometimes a button:</p>
  
  <p><img src="https://i.stack.imgur.com/7ftnb.png" alt="enter image description here"></p>
  
  <p>In my <code>UITableViewCell</code> subclass I have:</p>
  
  <pre><code>- (id)initWithFrame:(CGRect)frame
  {
      self = [super initWithFrame:frame];
      if ( self ) {
          // Initialization code
  
      firstLock = [[UILabel alloc]init];
      [firstLock setBackgroundColor:[UIColor clearColor]];
      firstLock.textAlignment = UITextAlignmentLeft;
      firstLock.font = [UIFont fontWithName:@"Arial-BoldMT" size:17];
  
      secondLock= [[UILabel alloc]init];
      [secondLock setBackgroundColor:[UIColor clearColor]];
      secondLock.textAlignment = UITextAlignmentRight;
      secondLock.font = [UIFont fontWithName:@"Arial-BoldMT" size:17];
  
      firstLockImage = [[UIImageView alloc]init];
  
      secondLockImage = [[UIImageView alloc] init];
  
      [self.contentView addSubview:firstLock];
      [self.contentView addSubview:secondLock];
      [self.contentView addSubview:firstLockImage];
      [self.contentView addSubview:secondLockImage];
      }
      return self;
  }
  </code></pre>
  
  <p>When one of the <code>UIImageView</code>s is just an image no problem, but it crashes when I add  a <code>UIButton</code> (imaged) as a subview.</p>
  
  <p>In the <code>UITableViewDataSource</code> implementation:</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
  
  
  
  UIImage *btnImage = [UIImage imageNamed:@"bike_ok.png"];
  
  UIButton *button =[UIButton alloc];
  [button setImage:btnImage forState:UIControlStateNormal];
  
  [cell.secondLockImage addSubview:button];
  </code></pre>
  
  <p>Adding a button as a subview of the image view crashes:</p>
  
  <pre><code> Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Requesting the window of a view (&lt;UIButton: 0x7bac7d0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; alpha = 0; opaque = NO; userInteractionEnabled = NO; layer = (null)&gt;) with a nil layer. This view probably hasn't received initWithFrame: or initWithCoder:.'
  *** First throw call stack:
  </code></pre>
  
  <p>What am I missing?</p>
  
  <p>Thanks!</p>
  
  <p>Just add! its important this line </p>
  
  <pre><code>    [firstLockImage setUserInteractionEnabled:YES];
      [secondLockImage setUserInteractionEnabled:YES];
  </code></pre>
  
  <p>Because the UIImageView has NO as default and the button doesn't work without it!</p>