简体   繁体   English

从parse-swift 2在UITextview中设置文本

[英]setting text inside UITextview from parse - swift 2

I'm trying to pass a string from Parse to my textview, it worked with uitextfield and it doesn't with uitextview. 我正在尝试将字符串从Parse传递到我的textview,它与uitextfield一起工作,而不是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). 看起来你正试图在后台线程上设置文本(可能是Web请求的完成处理程序)。 When you are updating UI elements you can only do so on the main thread. 更新UI元素时,只能在主线程上执行此操作。 So make sure that you are on the main thread when updating the UITextView : 因此,在更新UITextView时,请确保您在主线程上:

dispatch_sync(dispatch_get_main_queue(), ^{
    self.companyBackgroundTextview.text = (employerProfileObject.valueForKey("companyBackground")?.capitalizedString)! as String   
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM