2012-01-30 45 views
0
  • 在我的應用程序中,我有一個單元格樣式值爲2的表視圖:(單元格並排有兩個標籤)。
  • textLabel,我顯示的時間:顯示在timeLable中。
  • detailTextLable,我顯示這是在commentsTextView

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) 
{ 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease]; 
    cell.detailTextLabel.numberOfLines = 0; 
    cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap; 

} 

cell.textLabel.text = timelabel.text;    
cell.detailTextLabel.text = commentTextView.text; 
    } 
    //int x = cell.commentTextView.frame.size.height; 


} 

cell.detailTextLabel.textAlignment = UITextAlignmentLeft; 
cell.textLabel.textAlignment = UITextAlignmentLeft; 
return cell; 

}如何根據iPhone中的detailTextLabel中的文本大小增加單元格大小。


  • 我需要擴大我對於單元尺寸進入評論到樂在文本視圖中輸入的一系列註釋:detailTextLabel中顯示的「commentTextView」。

  • 但在textLable(timelable文本)的區別,它不隨detailTextLabel

擴大該怎麼辦?

回答

1

這樣做總是很棘手,因爲你需要做的高度是這樣的。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSString *myLabel = "Hello World"; 
    CGSize labelSize = [[myLabel sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:CGSizeMake(160,MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap]; 
    return labelSize.height; 
} 
+0

- (CGFloat的)的tableView:(UITableView的*)的tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 的NSString * cellText = nil; UIFont * cellFont = nil; cellText = commentsTextView.text; cellFont = [UIFont fontWithName:@「Helvetica-Bold」size:19.0]; CGSize constraintSize = CGSizeMake(280.0f,MAXFLOAT); CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap]; return labelSize.height + 10; } – 2012-01-30 12:19:39

+0

你的回答對我這個方面很有幫助 – 2012-01-30 12:20:13

1

您可以通過使用teble鑑於- (CGFloat)tableView:(UITableView *)t heightForRowAtIndexPath:(NSIndexPath *)indexPath delegae方法,像做: -

- (CGFloat)tableView:(UITableView *)t heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    CGSize lblSize ; 
    NSString *lblString ; 

    lblString = [[[dataSourceArray objectAtIndex:indexPath.row] valueForKey:@"aKey"]; 

    lblSize = [self getLebalSize:CGSizeMake(180, 9999) aLebalText:lblString aFont:[UIFont systemFontOfSize:15]]; 

    return lblSize.height + 10 ; 
} 

//getting labelsize 
- (CGSize) getLebalSize : (CGSize) maxSize aLebalText : (NSString *) lebalText aFont : (UIFont *) font 
{ 
    CGSize expectedLabelSize = [lebalText sizeWithFont:font constrainedToSize:maxSize lineBreakMode:UILineBreakModeTailTruncation]; 
    return expectedLabelSize; 
} 
+0

你的回答對我很有用,就像我這樣的感謝試試這麼多 - maulik – 2012-01-30 12:23:45

+0

歡迎你... – Maulik 2012-01-30 12:30:21

相關問題