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"];
此代码来 self 正在使用的教程,该教程在单元格内创建 subview 以添加一些文本。
但是,我想要做的不是添加文本,而是放置图像。
我尝试了 UIImageView *posterValue = [[UIImageView alloc] initWith... 哦,UIImageView 没有 initWithFrame。
也许有人可以解释图像的过程。我什至需要为 UIImageView 设置帧大小吗?我需要定位它。
编辑:
我的新代码:
UIImageView *posterValue = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,105,175)];
posterValue.tag = kPosterValueTag;
[cell.contentView addSubView:posterValue];
[posterValue release];
addSubView 不适用于 UIImageView。说 UIView 可能不响应 addSubView
最佳答案
是 addSubview 而不是 addSubView - 区分大小写。
关于iphone - 将图像添加到自定义单元格 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7124158/