2010-03-27 13 views

回答

1

不能展開細胞的寬度超過iPhone的屏幕...你可以做的是 1>使字體較小 2>讓你的文字多行

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

我認爲所有的細胞都需要是相同的高度和寬度。您可以使用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

我真的很喜歡這個解決方案。您可以簡單地返回任何浮點數以輕鬆更改單元格的高度。好簡單 – 2012-06-20 19:02:02

相關問題