2009-06-25 6 views
2

UITableViewCell 너비를 조정할 수 있는지 알고 싶습니다. 주소록의 연락처보기와 같이 이미지를 왼쪽에 넣고 싶습니다. 정확히 무엇을 달성하려고하는지 사진을 제공하는 here 게시물을 발견했습니다. 나는 또한이 게시물에 대한 답변을 확인하고 싶습니다.UITableViewCell 너비를 조정할 수 있습니까?

답변

2

OS3.0에는 원하는대로 할 수있는 API의 스타일 옵션이 있습니다.

또는, 당신은 내 cellForRowAtIndexPath에서이 작업을 수행 내 애플 리케이션 중 하나의 예를 들어 인터페이스 빌더에서 완전히 사용자 정의 테이블 뷰 셀을 만들 수 있습니다

PlaceViewCell *cell = (PlaceViewCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [self createNewPlaceCellFromNib]; 
} 

을 그리고이에서를 발굴 할 수있는 방법이다 012 NB

- (PlaceViewCell*) createNewPlaceCellFromNib { 
    NSArray* nibContents = [[NSBundle mainBundle] 
          loadNibNamed:@"PlaceCell" owner:self options:nil]; 
    NSEnumerator *nibEnumerator = [nibContents objectEnumerator]; 
    PlaceViewCell* placeCell = nil; 
    NSObject* nibItem = nil; 
    while ((nibItem = [nibEnumerator nextObject]) != nil) { 
     if ([nibItem isKindOfClass: [PlaceViewCell class]]) { 
      placeCell = (PlaceViewCell*) nibItem; 
      if ([placeCell.reuseIdentifier isEqualToString: @"Place" ]) { 
       //NSLog(@"PlaceCell - we have a winner!"); 
       break; // we have a winner 
      } else { 
       placeCell = nil; 
       NSLog(@"PlaceCell is nil!"); 
      } 
     } 
    } 
    return placeCell; 
} 

그런 다음 인터페이스 작성기에서 직접 UITableViewCell 하위 클래스를 만들 수 있습니다.

+0

유용한 API의 방향을 알려주는 마인드? 2.2/3.0 diff 문서를보고 새로운 스타일 옵션을 찾을 수 없습니다. 또한 Interface Builder에서 사용자 정의보기 셀을 만드는 것이 도움이됩니까? 셀을 만드는 데 문제가 없습니다. 너비를 조정하는 데 문제가 있습니다. –

+0

3.0에서 미리 정의 된 셀 뷰 스타일에 대한 자세한 내용은 Daskaja의 답변을 참조하십시오. – frankodwyer

0

IMO 당신은 UITableViewCell의 너비를 변경할 수 없지만 다행스럽게도 그렇게 할 필요는 없습니다. Apple은 셀의 왼쪽 테두리에 하나의 이미지를 표시 할 수있는 네 가지 기본 스타일을 제공합니다 (다른 위치에 배치하려는 경우 사용자 정의 레이아웃을 만들어야 함).

네 스타일 UITableViewCellStyle은 다음과 같습니다

  • UITableViewCellStyleDefault
  • UITableViewCellStyleSubtitle
  • UITableViewCellStyleValue1
  • UITableViewCellStyleValue2

당신이 오있는 UITableViewCell에 이미지를 삽입하려면 LD 사과 개발자 연결 네트워크에있는 TableView 프로그래밍 가이드를 읽어 Using Cell Objects in Predefined Styles

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    } 
    NSDictionary *item = (NSDictionary *)[self.content objectAtIndex:indexPath.row]; 
    cell.textLabel.text = [item objectForKey:@"mainTitleKey"]; 
    cell.detailTextLabel.text = [item objectForKey:@"secondaryTitleKey"]; 
    NSString *path = [[NSBundle mainBundle] pathForResource:[item objectForKey:@"imageKey"] ofType:@"png"]; 
    UIImage *theImage = [UIImage imageWithContentsOfFile:path]; 
    cell.imageView.image = theImage; 
    return cell; 
} 
+0

공유 해 주셔서 감사합니다. 그러나이를 수행하는 데 유용하지는 않습니다. 나는 내가 링크 된 그림의 그림처럼 셀의 바깥쪽에있는 그림을 (셀 바로 왼쪽으로 오프셋) 싶습니다. 다시 말하지만, 세포 안의 이미지를 원하지 않습니다. iPhone 또는 iPod touch에서 연락처를 열고 사람의 세부 정보로 이동하십시오.당신은 제가 거기에서 성취하려고하는 것을 정확히 볼 수 있습니다. 상단의 셀 왼쪽에 이미지 오프셋이 있습니다. –

+0

알았어.하지만 실제로 그 tableview 프로그래밍 가이드를 읽어야한다. 여기에 설명 된 방법 중에는 또 다른 방법이 있습니다. UITableViewCell을 완전히 하위 클래스로 만들면 렌더링하려는 대상이 완전히 자유 롭습니다. –

0

당신은 셀의 폭을 수정할 필요가 없습니다. 실제로 필요한 것은 셀 처럼 보이게하는 것입니다 (예 : 보이는 하위 뷰의 너비를 수정하여).

불행히도 링크가 작동하지 않아 더 구체적이지 않습니다.

tableView:indentationLevelForRowAtIndexPath: 방법을 사용하여 UITableViewDelegate 프로토콜을 시도해 볼 수도 있습니다.

관련 문제