0

这段代码有什么问题?不显示图像。感谢任何帮助...单步执行代码,我可以看到所有变量都已正确更新。代码执行没有任何错误。虽然没有看到图像。

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ModuleViewCellId];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ModuleViewCellId] autorelease];
}
NSUInteger row = [indexPath row];
NSDictionary *step = [self.module.steps objectAtIndex:row];
cell.textLabel.text = [step objectForKey:kStepTitleKey];//;
cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.backgroundColor = [UIColor clearColor];
cell.indentationWidth = 50;
cell.indentationLevel = 1;

//2/6 shp - add icons to the table view
NSString *imagename = [step objectForKey:kStepIconKey];
NSLog(@"%@",imagename);

UIImageView *image;

image = [[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 57, 57)] autorelease];
image.tag = 1000 + row;
image.contentMode = UIViewContentModeScaleAspectFit;
image.hidden = FALSE;


[image setImage: [UIImage imageNamed:imagename]];
[cell.contentView addSubview:image];


return cell;
}
4

2 回答 2

0

由于您使用的是默认单元格,即 uitableViewCell,因此请使用单元格的 imageview 属性。

UITableViewCell *cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.imageView.image = [UIImage imageNamed:@"ImageName"];
cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
于 2013-02-06T06:05:43.063 回答
0

我刚刚找到了答案。问题在于文件名的路径。我所有的图像文件都存储在一个包中。因此,即使正确引用了图像文件名,也需要附加路径。

以这种方式添加路径解决了问题。

    NSString *imagename = [NSString stringWithFormat: @"%@%@", @"Assets.bundle/assets_dir/",[step objectForKey:kStepIconKey]];

这个答案也帮助了我。 具有不同尺寸图像的 UITableViewCell

于 2013-02-06T05:41:15.310 回答