2011-01-21 3 views
1

나는 모든 기본 설정을 가진 table-cell을 가지고있다. 그리고 왼쪽의 ImageView에 이미지를 놓았고 TextLabel에 임의의 텍스트를 넣었습니다.iPhone에서 UITableViewCell의 이미지 뷰 고정?

아래의 방법으로 셀 높이를 조정합니다.

  • (CGFloat)를 tableView (jQuery과 *)를 tableView heightForRowAtIndexPath (NSIndexPath *) indexPath

문제는 좌측 이미지 뷰의 프레임 사이즈가 다른 셀의 높이에 의존이다.

아래 사진을 보면 4 번째 셀의 높이가 다른 것보다 크고 다른 이미지와 약간 닮았습니다.

이 문제의 원인은 무엇이며 어떻게 해결할 수 있습니까 ??

alt text

-이 내 cellForRowAtIndexPath 방법입니다

을 추가했다.


    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefaultt reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    cell.textLabel.numberOfLines = 0; 
    cell.textLabel.text = [self GetSelectionForRowAtIndexPath:indexPath]; 

    NSString *path = [[NSBundle mainBundle] pathForResource:@"icon_notSelected" ofType:@"png"]; 
    UIImage *theImage = [UIImage imageWithContentsOfFile:path]; 
    cell.imageView.image = theImage; 

이렇게하면 셀에 높이를 더 넣어도 imageView가 커지지 않습니다. 테이블의 각 셀에 이미지를 표시 할 경우 (NSIndexPath *) indexPath

: (jQuery과 *)있는 tableView cellForRowAtIndexPath : (있는 UITableViewCell *)있는 tableView -이 코드를 넣어

alt text

답변

0
UIImage *image = [UIImage imageNamed:@"your_image.png"]; 
cell.imageView.image = image; 

같은 줄에.

+0

물론, 저는 cellForRowAtIndexPath 메소드로 이미지를로드했습니다. 결과는 그 것입니다. – SeniorLee

0

코드를 통해서만 수행 할 수 있습니다. 이를 위해 IB가 필요 없습니다.

0

이미지보기에 고정 된 프레임을 지정하고 세로로 셀 가운데에 배치하십시오. 이 라인을 따라

뭔가 :

imageview.frame = CGRectMake(5, floor(cellHeight/2)-20, 40, 40); 

또는 단지가있는 UITableViewCell의 이미지 뷰 속성을 사용합니다.

+0

시도했지만 작동하지 않습니다. 어쩌면 imageView가 어딘가에 늘어져있을 수도 있습니다. – SeniorLee

관련 문제