[英]Adding an image to a custom cell subview
cellForRowAtIndexPath: 的cellForRowAtIndexPath:
CGRect nameValueRect = CGRectMake(80, 5, 200, 15);
UILabel *nameValue = [[UILabel alloc] initWithFrame:
nameValueRect];
nameValue.tag = kNameValueTag;
[cell.contentView addSubview:nameValue];
[nameValue release];
... ...
NSUInteger row = [indexPath row];
NSDictionary *rowData = [self.computers objectAtIndex:row];
UILabel *name = (UILabel *)[cell.contentView viewWithTag:
kNameValueTag];
name.text = [rowData objectForKey:@"Name"];
This code is from a tutorial that I'm using which creates a subview within the cell to add some text. 此代码来自我正在使用的教程,该教程在单元格中创建子视图以添加一些文本。
However, what I want to do is instead of adding text I will place an image. 但是,我想要做的不是添加文本而是放置图像。
I tried UIImageView *posterValue = [[UIImageView alloc] initWith... oh there's no initWithFrame for UIImageView. 我试过UIImageView * posterValue = [[UIImageView alloc] initWith ...哦,UIImageView没有initWithFrame。
Perhaps, someone can explain the process for an image. 也许,有人可以解释图像的过程。 Do I even need to set the frame size for a UIImageView?
我甚至需要为UIImageView设置帧大小吗? I would need to position it.
我需要定位它。
EDIT: 编辑:
my new code: 我的新代码:
UIImageView *posterValue = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,105,175)];
posterValue.tag = kPosterValueTag;
[cell.contentView addSubView:posterValue];
[posterValue release];
addSubView is not working for UIImageView. addSubView不适用于UIImageView。 Says UIView may not respond to addSubView
说UIView可能不响应addSubView
这是addSubview而不是addSubView - 案例很重要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.