简体   繁体   English

ios tableviewcell几个对象以编程方式一个单元格,以编程方式设置原型单元格,自定义表格视图单元格样式,

[英]ios tableviewcell several objects one a cell programatically , setting prototype cell programatically , custom table view cell style,

hello I built this tableview using the InterfaceBuilder and storyboard I used custom for the style of the cell and content prototype of the table view, this is the image: custom tableview 你好,我使用InterfaceBuilder和情节提要构建了这个tableview,我将custom用于表视图的单元格样式和内容原型,这是图像: custom tableview

but now I need to redo everything programmatically I tried insert an imageview in the cell using this code 但是现在我需要以编程方式重做所有事情,我尝试使用此代码在单元格中插入一个imageview

UIImageView *imgView = [[UIImageView alloc] initWithFrame:
  CGRectMake(300, 0, 80, 80)];
imgView.image = [UIImage imageNamed:@"esquina_estrella.png"];
cell.imageView.image = imgView.image;`

but the image stays static unresponsive to CGRectMake thanks for you help 但是图像保持静态,对CGRectM无响应感谢您的帮助

Add

imgView.clipsToBounds = YES;

To limit display of the image to the frame of the image view. 将图像的显示限制为图像视图的框架。

Also, you are adding the image of the image view to the cell's image view, which is a different object, without using your image view and its frame. 同样,您将图像视图的图像添加到单元格的图像视图(这是一个不同的对象),而无需使用图像视图及其框架。 You actually do not need an image view if you are just using the image. 如果您仅使用图像,则实际上不需要图像视图。 What you want is 你想要的是

cell.imageView = imgView;

or 要么

[cell.contentView addSubview:imgView]; 

The latter will be preferable if you want to place it exactly and add more image views as in your screen shot. 如果您想准确放置它并添加更多的图像视图(如屏幕截图),则最好使用后者。

Use this code to the Cell: 使用此代码到单元格:

// Make your frame origin 0,0 as below done.
UIImageView *imgView = [[UIImageView alloc] initWithFrame:
CGRectMake(0, 0, 80, 80)];

imgView.image = [UIImage imageNamed:@"esquina_estrella.png"];

[cell addSubview:imgView];
[imgView release]; 
imgView = nil;

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

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