TextView Getting Crash with long HTML text in iOS16

I am using textview in cell and making scrollable false. It is working fine up to iOS15, but getting crash in iOS16. If I am making textview scrollable to true, then it is not crashing but as soon as I am making textview scrollable false and start scrolling table view it is getting crashed. I need textview should not be scrollable .

Crash Logs:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(
	0  CoreFoundation           0x00007ff80041f225 __exceptionPreprocess + 242
	1  libobjc.A.dylib           0x00007ff800049c6f objc_exception_throw + 48
	2  CoreFoundation           0x00007ff8004a51a5 _CFThrowFormattedException + 200
	3  CoreFoundation           0x00007ff8004a2cc1 -[__NSArrayM insertObject:atIndex:].cold.2 + 0
	4  CoreFoundation           0x00007ff80030b2c4 -[__NSArrayM insertObject:atIndex:] + 993
	5  UIFoundation            0x00007ff8044c9086 __55-[__NSTextSelectionLineFragmentInfo _fetchCaretOffsets]_block_invoke + 980
	6  UIFoundation            0x00007ff804512117 __95-[NSTextLineFragment enumerateCaretOffsetsWithTextSelectionDataSource:baseLocation:usingBlock:]_block_invoke + 106
	7  CoreText              0x00007ff801966f07 _ZNKSt3__18functionIFvdlbPbEEclEdlbS1_ + 51
	8  CoreText              0x00007ff8019667b6 _ZNK5TLine21EnumerateCaretOffsetsENSt3__18functionIFvdlbPbEEE + 8290
	9  CoreText              0x00007ff801960f83 CTLineEnumerateCaretOffsets + 80
	10 UIFoundation            0x00007ff804511f29 -[NSTextLineFragment enumerateCaretOffsetsWithTextSelectionDataSource:baseLocation:usingBlock:] + 287
	11 UIFoundation            0x00007ff8044dd54a -[NSTextLayoutManager enumerateCaretOffsetsInLineFragmentAtLocation:usingBlock:] + 152
	12 UIFoundation            0x00007ff8044c8b6e -[__NSTextSelectionLineFragmentInfo _fetchCaretOffsets] + 379
	13 UIFoundation            0x00007ff8044c95d0 -[__NSTextSelectionLineFragmentInfo _cache] + 35
	14 UIFoundation            0x00007ff8044ca2ac -[__NSTextSelectionLineFragmentInfo indexForPrimaryLocation:] + 33
	15 UIFoundation            0x00007ff8044c9cee -[__NSTextSelectionLineFragmentInfo offsetForLocation:] + 22
	16 UIFoundation            0x00007ff8044d93fd __76-[NSTextLayoutManager enumerateTextSegmentsInRange:type:options:usingBlock:]_block_invoke_2 + 785
	17 UIFoundation            0x00007ff8045123e4 -[NSTextLineFragment enumerateTextSegmentBoundsInTextRange:withTextElementProvider:baseLocation:usingBlock:] + 535
	18 UIFoundation            0x00007ff8044d8f94 __76-[NSTextLayoutManager enumerateTextSegmentsInRange:type:options:usingBlock:]_block_invoke + 1404
	19 UIFoundation            0x00007ff8044d8692 -[NSTextLayoutManager enumerateTextSegmentsInRange:type:options:usingBlock:] + 1140
	20 UIKitCore              0x00000001190b7d80 -[NSTextLayoutManager(UIKitAdditions) ui_contentSizeForLastContainerView] + 507
	21 UIKitCore              0x00000001189b97a9 -[_UITextKit2LayoutController usedRectForTextContainer:] + 194
	22 UIKitCore              0x00000001193e8bfd -[_UITextContainerView textContainerOrigin] + 132
	23 UIFoundation            0x00007ff804532943 -[NSTextContainer textContainerOrigin] + 161
	24 UIKitCore              0x00000001188d3ba9 -[_UITextLayoutBaselineCalculator _baselineOffsetAtPosition:] + 791
	25 UIKitCore              0x00000001188d3dec -[_UITextLayoutBaselineCalculator firstBaselineOffsetFromTop] + 64
	26 UIKitCore              0x00000001193d9f04 __37-[UITextView _baselineOffsetsAtSize:]_block_invoke + 151
	27 UIKitCore              0x00000001193da2f0 __55-[UITextView _performTextKit2LayoutCalculation:inSize:]_block_invoke + 304
	28 UIKitCore              0x00000001189c44e5 +[UICalloutBar performWithoutAffectingSharedCalloutBar:] + 126
	29 UIKitCore              0x00000001193da19f -[UITextView _performTextKit2LayoutCalculation:inSize:] + 152
	30 UIKitCore              0x00000001193d9d03 -[UITextView _baselineOffsetsAtSize:] + 504
	31 UIKitCore              0x00000001193db774 -[UITextView _updateBaselineInformationDependentOnBounds] + 239
	32 UIKitCore              0x00000001194e63d2 __100-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:]_block_invoke_5 + 206
	33 UIKitCore              0x00000001194e613c -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:] + 991
	34 UIKitCore              0x00000001194e6f00 -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeededWithViewForVariableChangeNotifications:] + 374
	35 UIKitCore              0x00000001195e007e -[UIView _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 346
	36 UIKitCore              0x00000001195f3eb0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2413
	37 QuartzCore             0x00007ff80876c054 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 526
	38 UIKitCore              0x00000001195df801 -[UIView(Hierarchy) layoutBelowIfNeeded] + 1434
	39 UIKitCore              0x00000001195e6702 +[UIView(Animation) performWithoutAnimation:] + 84
	40 UIKitCore              0x0000000119265f46 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 2206
	41 UIKitCore              0x000000011924e209 -[UITableView _prefetchCellAtGlobalRow:aboveVisibleRange:] + 283
	42 UIKitCore              0x000000011924dfd9 __48-[UITableView _configureCellPrefetchingHandlers]_block_invoke + 50
	43 UIKitCore              0x00000001192a9aa8 -[_UITableViewPrefetchContext updateVisibleIndexRange:withContentOffset:] + 2577
	44 UIKitCore              0x000000011924e488 -[UITableView _updateCycleIdleUntil:] + 173
	45 UIKitCore              0x0000000118b02817 ___UIUpdateCycleNotifyIdle_block_invoke + 854
	46 libdispatch.dylib          0x000000010a7b1da8 _dispatch_call_block_and_release + 12
	47 libdispatch.dylib          0x000000010a7b2feb _dispatch_client_callout + 8
	48 libdispatch.dylib          0x000000010a7c3dad _dispatch_main_queue_drain + 1463
	49 libdispatch.dylib          0x000000010a7c37e8 _dispatch_main_queue_callback_4CF + 31
	50 CoreFoundation           0x00007ff80037fa33 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
	51 CoreFoundation           0x00007ff80037a402 __CFRunLoopRun + 2482
	52 CoreFoundation           0x00007ff800379673 CFRunLoopRunSpecific + 560
	53 GraphicsServices          0x00007ff809dc228e GSEventRunModal + 139
	54 UIKitCore              0x0000000118fe1ac9 -[UIApplication _run] + 994
	55 UIKitCore              0x0000000118fe69a0 UIApplicationMain + 123
Answered by ishteyaque in 717241022

Crash is not occurring if I am making UITextView isScrollable property to TRUE (which is not my requirement). I have fixed the issue by making isScrollable property to TRUE and re-calculating content size so that is scrolling behavior will not be visible.

When the text view is created, could you try accessing the layoutManager property on the UITextView? Does the crash still occur after accessing the property? In iOS 16, UITextView was updated to support TextKit 2, but if you access the layoutManager property, it falls back to TextKit 1 for compatibility reasons.

If you could file a bug report with a sample project and attach the feedback number here, that would also help.

Accepted Answer

Crash is not occurring if I am making UITextView isScrollable property to TRUE (which is not my requirement). I have fixed the issue by making isScrollable property to TRUE and re-calculating content size so that is scrolling behavior will not be visible.

Hello, I have the same issue after users start to update iOS to 16.2 In our project, UITextView uses using Attributed string to consume HTML content. The UITextView is placed in a UIListView.

HTML to crash:

<ul><li><p>Lorem ipsum, lorem ipsum</p></li></ul>

I have added this code to fix this.

       if #available(iOS 16.0, *) {

            // Hack to fallback to TextKit1

            _ = layoutManager

        }
TextView Getting Crash with long HTML text in iOS16
 
 
Q