iOS:UILabel sizeToFit随机崩溃

时间:2015-04-14 10:06:23

标签: ios uikit crashlytics

Crashlytics报告了一个崩溃,其中调用了[UILabel sizeToFit]方法。

下面的

是崩溃报告

Thread : Crashed: com.apple.main-thread
0  libsystem_kernel.dylib         0x0000000196edf270 __pthread_kill + 8
1  libsystem_pthread.dylib        0x0000000196f7d228 pthread_kill + 112
2  libsystem_c.dylib              0x0000000196e56b18 abort + 112
3  libsystem_malloc.dylib         0x0000000196f1a3e4 _nano_malloc_check_clear
4  libsystem_malloc.dylib         0x0000000196f192f8 nano_free + 192
5  CoreFoundation                 0x0000000185ff9a04 CFRelease + 1064
6  CoreText                       0x0000000186b09c44 TLine::~TLine() + 192
7  CoreFoundation                 0x0000000185ff9724 CFRelease + 328
8  UIFoundation                   0x0000000192f6f518 __NSStringDrawingEngine + 15728
9  UIFoundation                   0x0000000192f7153c -[NSAttributedString(NSExtendedStringDrawing) boundingRectWithSize:options:context:] + 636
10 UIKit                          0x000000018a8a7210 -[UILabel _textRectForBounds:limitedToNumberOfLines:includingShadow:] + 384
11 UIKit                          0x000000018a8a7088 -[UILabel textRectForBounds:limitedToNumberOfLines:] + 28
12 UIKit                          0x000000018a8a7004 -[UILabel _intrinsicSizeWithinSize:] + 136
13 UIKit                          0x000000018a8a6ea4 -[UIView(Geometry) sizeToFit] + 136
14 Shaadi                         0x00000001000e902c -[ProfileDetailsView tableView:cellForRowAtIndexPath:] (ProfileDetailsView.m:1690)
15 UIKit                          0x000000018ab9277c -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 544
16 UIKit                          0x000000018ab873a4 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2360
17 UIKit                          0x000000018a97d0ec -[UITableView layoutSubviews] + 172
18 UIKit                          0x000000018a899d00 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 572
19 QuartzCore                     0x000000018a1f1d58 -[CALayer layoutSublayers] + 168
20 QuartzCore                     0x000000018a1ec944 CA::Layer::layout_if_needed(CA::Transaction*) + 320
21 QuartzCore                     0x000000018a1ec7e8 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
22 QuartzCore                     0x000000018a1ebfe8 CA::Context::commit_transaction(CA::Transaction*) + 276
23 QuartzCore                     0x000000018a1ebd6c CA::Transaction::commit() + 436
24 QuartzCore                     0x000000018a2415a4 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 516
25 IOKit                          0x000000018725dd84 IODispatchCalloutFromCFMessage + 376
26 CoreFoundation                 0x00000001860bcf34 __CFMachPortPerform + 180
27 CoreFoundation                 0x00000001860d1b38 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56
28 CoreFoundation                 0x00000001860d1a98 __CFRunLoopDoSource1 + 436
29 CoreFoundation                 0x00000001860cfa18 __CFRunLoopRun + 1640
30 CoreFoundation                 0x0000000185ffd664 CFRunLoopRunSpecific + 396
31 GraphicsServices               0x000000018f1375a4 GSEventRunModal + 168
32 UIKit                          0x000000018a902984 UIApplicationMain + 1488
33 Shaadi                         0x00000001001394e0 main (main.m:16)
34 libdyld.dylib                  0x0000000196dc6a08 start + 4

这是一个代码块,根据崩溃的情况而崩溃

NSMutableArray *heights = [[NSMutableArray alloc] init];

UILabel *tmpLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 20)];
tmpLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:15];
tmpLbl.attributedText = [self getAttributedString:plainTxt];
tmpLbl.numberOfLines = 0;
tmpLbl.lineBreakMode = NSLineBreakByWordWrapping;
[tmpLbl sizeToFit];


-(NSMutableAttributedString *)getAttributedString:(NSString *)text
{
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:3];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];

    return attributedString;
}

[tmpLbl sizeToFit]

崩溃

这种随机崩溃的原因是什么?如何解决?

0 个答案:

没有答案