UITableviewCell图像大小变化点击单元格?

我想以正常的方式显示UITableViewCell中的名称和图像

cell.textLabel.text=@"some name"; cell.imageView.image=[array objectAtIndex:indexPath.row]; 

当我加载ViewController,我可以看到所有图像都正确,但当我试图点击任何UITableviewCell图像大小正在改变为大(请检查示例截图)。

请帮我解决这个问题。

加载时间看起来像

加载时间屏幕截图

当我点击第一个单元格时,单元格图像变得像下面的图像一样大 当我单击单元格时,单元格图像变大

请检查我的代码

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; cell.backgroundColor=[UIColor clearColor]; if(cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } cell.backgroundColor=[UIColor clearColor]; if([userName count]>0){ cell.textLabel.text=[userName objectAtIndex:indexPath.row]; [cell.imageView setImageWithURL:[NSURL URLWithString:[[userList valueForKey:@"photo"] objectAtIndex:indexPath.row]] placeholderImage:[UIImage imageNamed:@"avatar.png"]]; } CGSize itemSize = CGSizeMake(40, 40); UIGraphicsBeginImageContextWithOptions(itemSize, NO, UIScreen.mainScreen.scale); CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height); [cell.imageView.image drawInRect:imageRect]; cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); cell.imageView.layer.masksToBounds=YES; cell.imageView.layer.cornerRadius=9.0; return cell; } 

我的Didselect方法是这样的

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *nib; if ([[MyDevice getMyDevice] isiPad]) { nib = @"nibname_iPad"; } else { nib = @"nibname"; } ViewController *chat = [[ViewController alloc] initWithNibName:xibName bundle:[NSBundle mainBundle]]; chat.hidesBottomBarWhenPushed=YES; [self.navigationController pushViewController:chat animated:YES]; } 

尝试使用自定义单元格(更改单元格的属性检查器中单元格的样式),更好,可以按照自己的方式进行devise。 在故事板中创buildUILabels和UIImage(具有特定的宽度和高度),最后在UILabel和UIIamge的属性检查器中为它们设置一个特定的标签编号,这个编号对于它们都是唯一的。 并像这样访问它们:

在该方法中:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

插入这个:

  UITableViewCell *customCell = [self.tableView dequeueReusableCellWithIdentifier:@"theNameOfTheCell"]; UILabel *label; label = (UILabel *)[customCell viewWithTag:1]; label.text = @"Some text to label with tag number 1"; label = (UILabel *)[customCell viewWithTag:2]; label.text = @"Some text to label with tag number 2"; UIImageView *imageCell; imageCell = (UIImageView *)[customCell viewWithTag:3]; CALayer * l = [imageCell layer]; UIImage *cellImage = [UIImage imageNamed:@"theImageYouWant.png"]; imageCell.image = cellImage; 

尝试这个,并告诉什么追加,这是完整的文档: 官方文档表格视图单元格

添加内容模式:

 [cell.imageView setContentMode:UIViewContentModeScaleAspectFit]; 

希望这可以帮助… :)