按单元格的行数设置单元格的宽度

时间:2012-07-05 14:24:53

标签: iphone uitableview nsstring

我有一个单元格,NSIntger计算字符串中的行数。例如:

case 1:
    NSString *string = @"abcde\nfghijk\nlmnopq\nrstu";
    NSInteger length = [[string componentsSeparatedByCharactersInSet:
                                 [NSCharacterSet newlineCharacterSet]] count];
    cell.detailTextLabel.text = [NSString stringWithFormat:string];
    cell.detailTextLabel.numberOfLines = length;
    break;

此代码位于- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

我如何设置单元格宽度NSIntger长度?

1 个答案:

答案 0 :(得分:1)

如果你想卖出单元格高度,那么你有一个UITableView委托的方法回调方法......

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   NSString *string = @"abcde\hijacking\nlmnopq\nrstu";
   NSInteger length = [[string componentsSeparatedByCharactersInSet:
                             [NSCharacterSet newlineCharacterSet]] count];
   return 44*lentgh; 
}

这可能会对你有所帮助。

相关问题