【问题标题】:the UIImageView is not visible in the UITableViewCellUIImageView 在 UITableViewCell 中不可见
【发布时间】:2012-06-02 04:01:45
【问题描述】:

我在 UITableView 单元格中添加了一个 UIImageView,但它不可见。 但是当你选择了行时,图像是可见的,它是如此的不解。 你能帮助我吗 ?

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier: (NSString *) reuseIdentifier    
{  
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        cellImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"one.png"]];       
        cellImage.frame = CGRectMake(240, 0, 20, 20);
        [self.contentView addSubview:cellImage];
        self.textLabel.text = @"parent";
    }
    return self;
}

【问题讨论】:

    标签: ios uitableview uiimageview


    【解决方案1】:

    您只需将cellImage 添加为accessoryView

    [cell setAccessoryView: cellImage];
    

    【讨论】:

      【解决方案2】:

      你应该首先初始化你的 imageView 并设置它的 Frame 然后你应该设置它的图像。查看给定的 CustomtableViewCell 代码

      imgView = [[UIImageView alloc] initWithFrame:CGRectMake(3, 3, 80, 80)];
      imgView.contentMode = UIViewContentModeScaleAspectFit;
      [self.contentView addSubview:imgView];
      

      现在在控制器的 tableViewCellforrowatindexpath 方法中 使用给定的代码

      static NSString *CellIdentifier = @"Cell";
      
      CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      if (cell == nil) {
          cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
      }
      cell.imgView.image = [UIImage imageNamed:@"123.jpg"];
      

      这将在你的 imgView 添加图像

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多