2013-02-06 2 views
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; 
} 

답변

0

방금 ​​답변을 찾았습니다. 문제는 파일 이름에 대한 경로 때문입니다. 모든 이미지 파일은 번들에 저장됩니다. 따라서 이미지 파일 이름이 올바르게 참조 되더라도 경로를 추가해야했습니다.

경로를 이렇게 추가하면 문제가 해결됩니다.

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

이 답변도 도움이되었습니다. UITableViewCell with images in different dimensions

0

기본 셀 (예 : uitableViewCell)을 사용하고 있으므로 셀의 이미지 뷰 속성을 사용하십시오.

UITableViewCell *cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; 
cell.imageView.image = [UIImage imageNamed:@"ImageName"]; 
cell.imageView.contentMode = UIViewContentModeScaleAspectFit; 
관련 문제