title: How do I center a UIImage inside a UITableView cell?
body: <p>I am trying to center all the UIImage images in my UITableView cell, but cannot achieve the results.</p>
  
  <p>I tried searching for suggestions/solutions and found several, but nothing works.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
      return [array count];
  }
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      static NSString *CellIdentifier = @"Cell";
  
  
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  
      if (cell == nil)
      {
          cell = [ [UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  
      }
  
      cell.backgroundColor = [UIColor clearColor];
  
      cell.imageView.image = [UIImage imageNamed:[sponsorsLogoArray objectAtIndex:indexPath.row]];
  
      return cell;
  }
  
  - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
      return indexPath;
  }
  </code></pre>
  
  <p>Added the following code:</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      ....
      //cell.imageView.image = [UIImage imageNamed:[sponsorsLogoArray objectAtIndex:indexPath.row]];
      UIImageView *pic = [ [UIImageView alloc] initWithImage:[array objectAtIndex:indexPath.row]];
      [cell.contentView addSubview:pic];
      pic.center = CGPointMake(cell.contentView.bounds.size.width/2,cell.contentView.bounds.size.height/2);
  
      ....
  }
  </code></pre>
  
  <p>And also tried:</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      ....
      //cell.imageView.image = [UIImage imageNamed:[array objectAtIndex:indexPath.row]];
      UIImageView *pic = [ [UIImageView alloc] initWithImage:[array objectAtIndex:indexPath.row]];
      pic.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
      [cell.contentView addSubview:pic];
      pic.center = CGPointMake(cell.contentView.bounds.size.width/2,cell.contentView.bounds.size.height/2);
  
      ....
  }
  </code></pre>
  
  <p>And also:</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      ....
      //cell.imageView.image = [UIImage imageNamed:[array objectAtIndex:indexPath.row]];
      UIImageView *pic = [ [UIImageView alloc] initWithImage:[array objectAtIndex:indexPath.row]];
      pic.center = CGPointMake(cell.contentView.bounds.size.width / 2 , 60);
      pic.contentMode = UIViewContentModeScaleAspectFit;
      cell.selectionStyle = UITableViewCellSelectionStyleGray;
      [cell.contentView addSubview:pic];
  
      ....
  }
  </code></pre>
  
  <p>all 3 times received error:</p>
  
  <blockquote>
    <p>*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString
    _isDecompressing]: unrecognized selector sent to instance 0x10036ada0'</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>