2012-01-30 43 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

相关问题