2013-04-11 3 views
1

Xcode 초보자로서 내 앱의 표 셀에 미리보기 이미지를 표시하고 싶습니다. 지금은 JSON 데이터를 구문 분석하여 셀의 제목과 부제목에 게시하는 코드가 있습니다.어떻게 xCode의 표 셀에 축소판 이미지를 표시 할 수 있습니까?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"]; 

    if(cell == nil){ 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MainCell"]; 
    } 

    cell.textLabel.text = [[news objectAtIndex:indexPath.row] objectForKey:@"receta"]; 
    cell.detailTextLabel.text = [[news objectAtIndex:indexPath.row] objectForKey:@"koha"]; 

    return cell; 
} 

어떻게하면 셀 오른쪽에 축소판을 표시 할 수 있습니까?

감사합니다.

+0

자신의 레이아웃과 함께 사용할 수있는 사용자 지정 셀을 만듭니다. Google에서 사용자 정의 UITableViewCells를 검색하십시오. – Popeye

+0

뽀빠이, 이걸 도와 주겠니? 검색했지만 Xcode에 대해 조금 알고 있기 때문에 유용하지 않습니다. 오늘 열어 볼 세 번째입니다. –

+0

나는 약간의 튜토리얼을 추천합니다. 다음은 좋은 자습서입니다. http://blog.spritebandits.com/2012/03/13/creating-custom-uitableviewcells-from-xibs-step-by-step-tutorial/ – Popeye

답변

3

맞춤 셀을 만들고 싶지 않은 경우 원하는 이미지로 UIImageView을 만들고 셀의 오른쪽 가장자리에 표시 할 셀 accessoryView으로 설정할 수 있습니다. 또한 셀의 높이가 이미지의 높이에 맞을만큼 충분히 크지 않은지 확인해야합니다.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return 100; 
} 

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"some-image-name"]]; 

    return cell; 
} 

이미지가 항상 고정 된 크기가됩니다 경우는 상수 (나는 100를 선택) 반환 할 수 있습니다, 또는 당신이 UIImagesize을 확인하고 몇 가지 여분의 패딩 size.height + 10 뭔가를 반환 할 수 있습니다.

+0

'accessoryView'는 있지만 그것을 할 것입니다. +1 상자 밖 생각을 위해. – Popeye

+0

Amar가 맞춤 셀을 만들고 싶지 않다면 한 가지 방법입니다. – jszumski

관련 문제