2010-03-27 5 views

답변

1

당신은 아이폰의 화면보다 더 많은 셀의 폭을 확장 할 수 없습니다 ... 당신이 할 수있는 것은

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    CGRect contentRect = CGRectMake(80.0, 0.0, 240, 40); 
    UILabel *textView = [[UILabel alloc] initWithFrame:contentRect]; 

    textView.text = mytext; 
    textView.numberOfLines = 2; 
    textView.textColor = [UIColor grayColor]; 
    textView.font = [UIFont systemFontOfSize:12]; 
     [cell.contentView addSubview:textView]; 
    [textView release]; 
0

나는 모든 셀이 필요하다고 생각 1>은 2>는 텍스트 여러 줄 수 있도록 폰트 작게 만들 것입니다 높이와 너비가 같아야합니다. tableView's rowHeight 속성을 사용하여 UITableViewCells의 높이를 변경할 수 있습니다. 예를 들어

, 당신은 UITableViewController

self.tableView.rowHeight = 100;

또 다른 옵션은 앞에 나온 좋아 내용 없음 세포의 하위 뷰 같은 사용자 정의 UILabel을 추가하는 것입니다 서브 클래스합니다.

2

나는 당신이해야 할 노력하고 정확하게하려고 노력하지 않은,하지만 아마 이런 식으로 뭔가 갈 것 : 당신은 텍스트 문자열의 길이에 따라 뷰의 크기를 변경해야

을 그 안에.

테이블 뷰 위임 (보기 컨트롤러) 각 행을 만드는 방법 키보기를 알려줍니다

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    Message *msg = (Message *)[messages objectAtIndex:indexPath.row]; 
    CGSize size = [[msg text] sizeWithFont:[UIFont fontWithName:@"Helvetica" size:kLabelFontSize] 
         constrainedToSize:CGSizeMake(220.0f, 480.0f) 
          lineBreakMode:UILineBreakModeTailTruncation]; 
    CGFloat minHeight = 20.0f; 
    CGFloat height = size.height > minHeight ? size.height : minHeight; 
    return height; 
} 

를 구현해야합니다.

마찬가지로 UITableViewCell 레이블의 프레임 크기를 조정해야 할 필요가 있습니다.

+0

정말이 솔루션을 좋아합니다. 모든 플로트를 반환하여 셀 높이를 쉽게 변경할 수 있습니다. 아주 쉽게 –

관련 문제