2011-08-20 48 views
0

我使用UITableView代表来动态调整我的UITableViewCells的大小,但由于某种原因,下面一段代码给了我一个中止信号。它有什么明显的问题吗?几行代码导致一个SIGABRT

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSString *comment = [_comments objectAtIndex:indexPath.row]; 
    CGSize expectedLabelSize = [comment sizeWithFont:[UIFont boldSystemFontOfSize:12.0] constrainedToSize:CGSizeMake(250, CGFLOAT_MAX) lineBreakMode:UILineBreakModeWordWrap]; 
    return expectedLabelSize.height; 

} 
+1

你很少会得到一个没有错误信息的SIGABRT。检查控制台的日志,很可能是未捕获的异常。 – ughoavgfhw

+0

'_comments'可能是一个指向释放对象的指针,但除非您确定这是导致崩溃的行并显示如何创建,填充和释放'_comments',否则不可能说。 – Jonah

+0

@Jonah @ughoavgfhw它是'CGSize'行。 '_comments'没有解除分配。虽然找到了答案!我添加了一个'comment'字符串的'NSLog',并发现这个字符串等于''或者其他的行。从'[comment sizeWithFont:[UIFont boldSystemFontOfSize:12.0]''将'CGSize'赋值改为'[[comment sizeWithFont:[UIFont boldSystemFontOfSize:12.0] text]''解决了这个问题。任何人都可以解释发生在那里的事情吗? –

回答

0

改变CGSize分配到

[[comment sizeWithFont:[UIFont boldSystemFontOfSize:12.0] text]

[comment sizeWithFont:[UIFont boldSystemFontOfSize:12.0]固定它。

+1

这是如何解决它的?看起来你正试图在CGSize上调用'text'! –

+0

@josh查看原始代码片段。 –