2012-07-05 56 views
0

我有一个单元格和一个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长度?

+2

你想要单元格宽度或单元格高度? – Abhishek 2012-07-05 14:26:32

+0

这个问题很含糊。我也没有看到'[NSString stringWithFormat:string]'的原因... ... – 2012-07-05 14:27:37

+0

啊..是的....抱歉。我想要细胞的高度。 和@ H2CO3 - 我只是对代码进行抽样。 – theShay 2012-07-05 14:29:30

回答

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; 
} 

可能这会帮助你。

+0

它为你工作? – Abhishek 2012-07-05 14:37:18

+0

是的。以及如何编辑细胞高度? – theShay 2012-07-05 14:38:02

+0

我没有真正明白你的观点。如果它正在工作,你可以正确地标记在这...并请解释你现在想要的是什么 – Abhishek 2012-07-05 14:40:21