2014-04-05 3 views
0

안녕하세요 저는 기본 셀 높이 44.0로가 UITable 전망을 가지고 지금 우리는 같은 셀 내용에 따라이 증가 할 이미지로 내가 이것을 사용하고 있지만이 작동하지 않습니다 enter image description hereUITable보기 셀 높이를 늘리는 방법 적합한 셀 내용에 따라 런타임?

.....

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    int rowHeight =0.0f; 
// NSString *stringToSize = [shared.combine_address objectAtIndex:indexPath.row]; 
CGSize size = [ [shared.combine_address objectAtIndex:indexPath.row] sizeWithFont:[UIFont systemFontOfSize:13.0f] constrainedToSize:CGSizeMake(743, 44) lineBreakMode:NSLineBreakByWordWrapping]; 
rowHeight = self.table.rowHeight+size.height; 
return rowHeight; 
} 


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

static NSString *MyIdentifier = @"MyIdentifier"; 

// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 

SWTableViewCell *cell2 = (SWTableViewCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 


if(tableView==table) 
{ 
    //static NSString *cellIdentifier = @"Cell"; 

    if (cell2 == nil) { 

     cell2 = [[SWTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
             reuseIdentifier:MyIdentifier 
            containingTableView:table // Used for row height and selection 
            leftUtilityButtons:nil 
            rightUtilityButtons:[self rightButtons]]; 
     cell2.delegate = self; 
     cell2.selectionStyle=UITableViewCellSelectionStyleNone; 
    } 
    NSLog(@"CELL 1 %@",cell2.textLabel.text); 
    cell2.textLabel.lineBreakMode=NSLineBreakByWordWrapping; 
    cell2.textLabel.numberOfLines=0; 
    cell2.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f]; 
    cell2.detailTextLabel.lineBreakMode = NSLineBreakByWordWrapping; 
    cell2.detailTextLabel.numberOfLines = 0; 
    [cell2.textLabel sizeToFit]; 

} 
return cell2; 

} 
+0

일회 검사 CGSizeMake (743, 44) 가치 라벨 폭은 귀하의 경우 743이어야합니다. – Balu

+0

이 답변을 업데이트했습니다. 다른 방법을 시도해보십시오. – Selvin

+0

cellforrowindexpath 코드를 추가 하시겠습니까? – NANNAV

답변

0

너비가 잘못되었거나 shared.combineAddress에 값이 없습니다. stringToSize이 약간 값이있는 경우 320

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    int rowHeight =0.0f; 
    NSString *stringToSize = [shared.combine_address objectAtIndex:indexPath.row]; 
    CGSize size = [stringToSize sizeWithFont:[UIFont systemFontOfSize:13.0f] constrainedToSize:CGSizeMake(320, 44) lineBreakMode:NSLineBreakByWordWrapping]; 
    rowHeight = self.table.rowHeight+size.height; 
    return rowHeight; 
} 

또한 검사로

시도주는 폭입니다.

편집 :

UILabel *sizeCalculationLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 0)]; 
    sizeCalculationLabel.numberOfLines = 0; 
    [sizeCalculationLabel setFont:[UIFont systemFontOfSize:13.0f]]; 
    sizeCalculationLabel.text = stringToSize; 
    [sizeCalculationLabel sizeToFit]; 
    return sizeCalculationLabel.frame.size.height; 
+0

shared.combine_address에는 값이 있으며 이미 수행했지만 작동하지는 않습니다. – rahul

+0

@Selvin 나는 이것이 모든 셀에 대해 올바른 접근이라고 생각하지 않는다. 라벨을 초기화 할 것이다. 필요하지 않은 Object를 만드는 프로세스입니다. 또한 그것은 당신의 기억력을 증가시킬 것입니다. –

0

은 당신이 아이 패드를 사용하고 생각합니다. UITableView의 너비가 743 이상이면 다음을 변경할 수 있습니다.

변경 constrainedToSize:CGSizeMake(743, 44) 값을 constrainedToSize:CGSizeMake(743, 999)으로 변경하십시오.

너비를 tableView 너비로 전달했는지 확인하십시오. 그래서 귀하의 UITableView의 높이가 constrainedToSize:CGSizeMake(320, 999)보다 320 (iPhone의 경우 표준) 인 경우.

너비가 44 인 제한된 크기를 전달하면 최대 높이가 44가되어야한다고 표시되므로 표시하려는 최대 크기는 100, 200 또는 임의의 숫자가 될 수 있습니다.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    int rowHeight =0.0f; 
    CGSize size; 
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { 
     NSDictionary *stringAttributes = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:13.0f] forKey: NSFontAttributeName]; 
     size = [[shared.combine_address objectAtIndex:indexPath.row] boundingRectWithSize:CGSizeMake(743, 999) options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin attributes:stringAttributes context:nil].size; 

    } 
    else { 
     size = [ [shared.combine_address objectAtIndex:indexPath.row] sizeWithFont:[UIFont systemFontOfSize:13.0f] constrainedToSize:CGSizeMake(743, 999) lineBreakMode:NSLineBreakByWordWrapping]; 
    } 
    rowHeight = self.table.rowHeight+size.height; 
    return rowHeight; 
} 
: 나는 또한 999

sizeWithFont로 설정하고 여기에

아이폰 OS 7에

- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context

를 사용하는 아이폰 OS 7 그래서 더 나은에서 더 이상 사용되지 않습니다은 예입니다

0

테이블 뷰 셀 사용 동적 높이 UITableViewAutomaticDimension

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 

return UITableViewAutomaticDimension; 
} 

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{ 

return 44.0f; 

} 
관련 문제