Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [160 nan]解決方案

來源:互聯網
上載者:User

標籤:style   blog   http   color   使用   strong   

 1 2014-06-11 15:19:17.167 ***[930:707] *** Terminating app due to uncaught exception ‘CALayerInvalidGeometry‘, reason: ‘CALayer position contains NaN: [160 nan]‘   2 *** Call stack at first throw:   3 (   4     0   CoreFoundation                      0x3365d64f __exceptionPreprocess + 114   5     1   libobjc.A.dylib                     0x33aa0c5d objc_exception_throw + 24   6     2   CoreFoundation                      0x3365d491 +[NSException raise:format:arguments:] + 68   7     3   CoreFoundation                      0x3365d4cb +[NSException raise:format:] + 34   8     4   QuartzCore                          0x361db61d _ZL18CALayerSetPositionP7CALayerRKN2CA4Vec2IdEEb + 140   9     5   QuartzCore                          0x361db58b -[CALayer setPosition:] + 38  10     6   QuartzCore                          0x361db4d7 -[CALayer setFrame:] + 390  11     7   UIKit                               0x330eb455 -[UIView(Geometry) setFrame:] + 188  12     8   UIKit                               0x3314854f -[UITableViewCell setFrame:] + 98  13     9   UIKit                               0x33147b3b -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 850  14     10  UIKit                               0x3314776b -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 34  15     11  UIKit                               0x331400cd -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 936  16     12  UIKit                               0x3313f27d -[UITableView layoutSubviews] + 140  17     13  UIKit                               0x330eb5fb -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 26  18     14  CoreFoundation                      0x335caf03 -[NSObject(NSObject) performSelector:withObject:] + 22  19     15  QuartzCore                          0x361dcbb5 -[CALayer layoutSublayers] + 120  20     16  QuartzCore                          0x361dc96d CALayerLayoutIfNeeded + 184  21     17  QuartzCore                          0x361e21c5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 212  22     18  QuartzCore                          0x361e1fd7 _ZN2CA11Transaction6commitEv + 190  23     19  QuartzCore                          0x361db055 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 56  24     20  CoreFoundation                      0x33634a35 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 16  25     21  CoreFoundation                      0x33636465 __CFRunLoopDoObservers + 412  26     22  CoreFoundation                      0x3363775b __CFRunLoopRun + 854  27     23  CoreFoundation                      0x335c7ec3 CFRunLoopRunSpecific + 230  28     24  CoreFoundation                      0x335c7dcb CFRunLoopRunInMode + 58  29     25  GraphicsServices                    0x3413041f GSEventRunModal + 114  30     26  GraphicsServices                    0x341304cb GSEventRun + 62  31     27  UIKit                               0x33114d69 -[UIApplication _run] + 404  32     28  UIKit                               0x33112807 UIApplicationMain + 670  33     29  PXiPhone                            0x000028df main + 70  34     30  PXiPhone                            0x00002894 start + 40  35 )  36 terminate called after throwing an instance of ‘NSException  

今天,加完一個功能,在iPhone4上報以上異常,然後crash掉,iPhone3上沒事。百思不得其解,於是google之。看了一篇stackoverflow.com 的文章,說是某些地方代碼除以0了,多見於自訂的UITableView自訂UITableViewCell高度的地方,如:tableView:heightForHeaderInSection:或tableView:heightForFooterInSection:。這兩個delegate方法都沒有地方需要除的。在仔細看一下文章,說多見於適用sizeWithFont方法計算UILabel寬高的地方。恍然大悟,小弟有一個地方使用了UILabel來顯示文本,需要用到sizeWithFont方法計算寬高的,在NSString為nil的時候,sizeWithFont會除以0了。

原文:http://blog.csdn.net/hanspy/article/details/6538156

PS:在使用sizeWithFont計算UItabelView中label中字的長度時,由於表視圖的cell是複用的,所以在計算label中的NSString的長度時,NSString可能為nil,此時可能會除以0,便會報錯。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.