I'm trying to pass a string from Parse to my textview, it worked with uitextfield and it doesn't with uitextview.
Here is the code,
self.companyBackgroundTextview.text = (employerProfileObject.valueForKey("companyBackground")?.capitalizedString)! as String
The code above's returning an error .This is the error,
2015-10-29 13:36:38.592 TestView[5033:290374] *** Assertion failure in void _UIPerformResizeOfTextViewForTextContainer(NSLayoutManager *, UIView<NSTextContainerView> *, NSTextContainer *, NSUInteger)(), /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIFoundation_Sim/UIFoundation-432/UIFoundation/TextSystem/NSLayoutManager_Private.m:1551
2015-10-29 13:36:38.605 TestView[5033:290374] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only run on the main thread!'
*** First throw call stack:
(
0 CoreFoundation 0x000000010d70ef45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010d186deb objc_exception_throw + 48
2 CoreFoundation 0x000000010d70edaa +[NSException raise:format:arguments:] + 106
3 Foundation 0x000000010cdd26b2 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 169
4 UIFoundation 0x0000000113ffaa7f -[NSLayoutManager(NSPrivate) _resizeTextViewForTextContainer:] + 409
5 UIFoundation 0x0000000113ffa7a1 -[NSLayoutManager(NSPrivate) _recalculateUsageForTextContainerAtIndex:] + 2397
6 UIFoundation 0x00000001140331fa -[NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:] + 747
7 UIFoundation 0x00000001140332d2 -[NSLayoutManager processEditingForTextStorage:edited:range:changeInLength:invalidatedRange:] + 47
8 UIFoundation 0x000000011405aa76 -[NSTextStorage _notifyEdited:range:changeInLength:invalidatedRange:] + 152
9 UIFoundation 0x000000011405a591 -[NSTextStorage processEditing] + 349
10 UIFoundation 0x000000011405a1eb -[NSTextStorage endEditing] + 82
11 UIKit 0x000000010e5f4f2c -[UITextView setAttributedText:] + 250
12 UIKit 0x000000010e5fcb31 -[UITextView setText:] + 188
13 TestView 0x000000010b843333 _TFFC8Occupost18ProfileEmployerTVC9fetchDataFS0_FT_T_U_FT_T_ + 4467
14 TestView 0x000000010b7e0997 _TTRXFo__dT__XFdCb__dT__ + 39
15 libdispatch.dylib 0x000000010f7ece5d _dispatch_call_block_and_release + 12
16 libdispatch.dylib 0x000000010f80d49b _dispatch_client_callout + 8
17 libdispatch.dylib 0x000000010f7f5bef _dispatch_root_queue_drain + 1829
18 libdispatch.dylib 0x000000010f7f54c5 _dispatch_worker_thread3 + 111
19 libsystem_pthread.dylib 0x000000010fb554f2 _pthread_wqthread + 1129
20 libsystem_pthread.dylib 0x000000010fb53375 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Looks like you are trying to set the text on a background thread (probably the completion handler of a web request). When you are updating UI elements you can only do so on the main thread. So make sure that you are on the main thread when updating the UITextView
:
dispatch_sync(dispatch_get_main_queue(), ^{
self.companyBackgroundTextview.text = (employerProfileObject.valueForKey("companyBackground")?.capitalizedString)! as String
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.