我在crashlytics中遇到了原始错误。
基本上我正在尝试计算tableview" heightForRowAtIndexPath"中的标签高度。通过将相同的文本分配给另一个uilabel并获得其高度作为回报,因此我可以相应地为单元格指定高度
Thread : Crashed: com.apple.main-thread
0 libsystem_kernel.dylib 0x0000000193533270 __pthread_kill + 8
1 libsystem_pthread.dylib 0x00000001935d1228 pthread_kill + 112
2 libsystem_c.dylib 0x00000001934aab18 abort + 112
3 libsystem_malloc.dylib 0x000000019356e3e4 _nano_malloc_check_clear
4 libsystem_malloc.dylib 0x000000019356d2f8 nano_free + 192
5 CoreFoundation 0x000000018258d444 CFRelease + 1064
6 CoreText 0x00000001830a1c18 TLine::~TLine() + 192
7 CoreFoundation 0x000000018258d164 CFRelease + 328
8 UIFoundation 0x000000018f697c68 __NSStringDrawingEngine + 15728
9 UIFoundation 0x000000018f699c8c -[NSAttributedString(NSExtendedStringDrawing) boundingRectWithSize:options:context:] + 636
10 UIKit 0x0000000186e672f0 -[UILabel _textRectForBounds:limitedToNumberOfLines:includingShadow:] + 384
11 UIKit 0x0000000186e67168 -[UILabel textRectForBounds:limitedToNumberOfLines:] + 28
12 UIKit 0x0000000186e670e4 -[UILabel _intrinsicSizeWithinSize:] + 136
13 UIKit 0x0000000186e66f84 -[UIView(Geometry) sizeToFit] + 136
14 Shaadi 0x000000010015fb70 -[ProfileDetailsView heightOfLabelNew:withWidth:withLines:] (ProfileDetailsView.m:674)
15 Shaadi 0x000000010016058c -[ProfileDetailsView tableView:heightForRowAtIndexPath:] (ProfileDetailsView.m:808)
16 UIKit 0x0000000186f75b7c __66-[UISectionRowData refreshWithSection:tableView:tableViewRowData:]_block_invoke + 500
17 UIKit 0x0000000186f379bc -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 3872
18 UIKit 0x00000001872411e8 -[UITableViewRowData _ensureSectionOffsetIsValidForSection:] + 180
19 UIKit 0x0000000186f36a04 -[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:] + 396
20 UIKit 0x0000000186f36814 -[UITableViewRowData heightForTable] + 64
21 UIKit 0x0000000186f36620 -[UITableView _updateContentSize] + 244
22 UIKit 0x0000000186f3c5f4 -[UITableView didMoveToWindow] + 88
23 UIKit 0x0000000186e595f8 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1464
24 UIKit 0x0000000186e7aa34 -[UIScrollView _didMoveFromWindow:toWindow:] + 68
25 UIKit 0x0000000186e59310 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
26 UIKit 0x0000000186e589e0 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 144
27 UIKit 0x0000000186e588c0 -[UIView(Hierarchy) _postMovedFromSuperview:] + 484
28 UIKit 0x0000000186e643a0 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1764
29 Shaadi 0x000000010020a148 -[PartnerProfileViewController addFullProfileDetailsAtPage:profileDetails:] (PartnerProfileViewController.m:838)
30 Shaadi 0x0000000100209bf8 __62-[PartnerProfileViewController addProfilePage:profileDetails:]_block_invoke (PartnerProfileViewController.m:782)
31 libdispatch.dylib 0x00000001933f13ac _dispatch_call_block_and_release + 24
32 libdispatch.dylib 0x00000001933f136c _dispatch_client_callout + 16
33 libdispatch.dylib 0x00000001933f5980 _dispatch_main_queue_callback_4CF + 932
34 CoreFoundation 0x0000000182665fa4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
35 CoreFoundation 0x000000018266404c __CFRunLoopRun + 1492
36 CoreFoundation 0x00000001825910a4 CFRunLoopRunSpecific + 396
37 GraphicsServices 0x000000018b7335a4 GSEventRunModal + 168
38 UIKit 0x0000000186ec2aa4 UIApplicationMain + 1488
39 Shaadi 0x00000001001b2b64 main (main.m:16)
40 libdyld.dylib 0x000000019341aa08 start + 4
我无法理解此错误的原因,但似乎发生在[uilable sizeToFit]
请帮助我理解这可能是什么原因。
========更新==========
-(NSMutableArray *)heightOfLabelNew:(NSString *)plainTxt withWidth: (CGFloat)width withLines:(int)lines
{
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];
[heights addObject:[NSNumber numberWithFloat:tmpLbl.frame.size.height]];
tmpLbl.numberOfLines = lines;
[tmpLbl sizeToFit];
[heights addObject:[NSNumber numberWithFloat:tmpLbl.frame.size.height]];
return heights;
}
-(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;
}
Crashlytics显示代码的行数" [tmpLbl sizeToFit];"