简体   繁体   English

表格视图单元格中的图像

[英]Image in the Tableview cell

Hi i am a newbie to iOS. 嗨,我是iOS的新手。

I have implemented a tableview in ViewController1.In the tableview i am displaying tittle,detailText and disclosure indicator for the cell. 我已经在ViewController1中实现了一个tableview.tableview我正在显示单元格的标题,detailText和公开指示器。

- (UITableViewCell *)tableView:(UITableView *)tableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

if (cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
                                   reuseIdentifier:MyIdentifier];
}



cell.textLabel.text =[listTableArray objectAtIndex:indexPath.row];
cell.textLabel.textColor=[UIColor grayColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

  cell.detailTextLabel.text=@"4mile";





return cell;
}

Everything works fine,Now i need a image before the disclosure indicator when i do it with 一切正常,现在当我这样做时,我需要在公开指示符之前有图像

 UIImageView *accessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
  accessoryView.image=[UIImage imageNamed:@"list.png"];
cell.accessoryView = accessoryView;

Disclosure indicator is replaced by the image.But i need both image along with disclosure indicator without using Custom cell. 披露指示器已替换为image。但是我需要两个图像以及披露指示器,而无需使用“自定义”单元格。

How can i do it...? 我该怎么做...? Help me out. 帮帮我。

Thanks 谢谢

在此处输入图片说明

similiar to the due date but at the place of time i need image 与到期日相似,但在时间上我需要图像

If you wanna add UIImageView to standard UITableViewCell you need add your imageView to contentView of cell and add all subviews like a textLabel , detailTextLabel and accessoryView 如果你想添加UIImageView标准UITableViewCell您需要添加imageViewcontentView细胞并添加所有子视图就像一个textLabeldetailTextLabelaccessoryView

UIImageView *accessoryImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
accessoryImageView.image=[UIImage imageNamed:@"list.png"];
[cell.contentView addSubview:accessoryImageView];

or subclass of UITableViewCell and implement all views inside it UITableViewCell子类,并在其中实现所有视图

UITableViewCell have a fixed layout, depending on the style you use when you initialize it. UITableViewCell具有固定的布局,具体取决于初始化时使用的样式。 You cannot change that layout, since the cell lays out its subviews as it prefers to have them. 您无法更改该布局,因为单元会按其喜欢的方式布置其子视图。

add the - (void)layoutSubviews to your cell subclass like this: - (void)layoutSubviews添加到您的单元格子类中,如下所示:

- (void)layoutSubviews {
    [super layoutSubviews];
    self.imageView.frame = CGRectMake(0.0f , 0.0f, 20.0f, 20.0f);
}

else try this 否则尝试这个

 UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = [UIImage imageNamed:@"list.png"];;
[imageView setFrame:CGRectMake(50, 5, 20, 20)]; // customize the frame
 [cell.contentView addSubview:imageView];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM