2015-10-29 35 views
1

我想從Parse傳遞一個字符串到我的textview,它與uitextfield一起工作,它不與uitextview。從解析設置UITextview裏面的文本 - swift 2

下面是代碼,

self.companyBackgroundTextview.text = (employerProfileObject.valueForKey("companyBackground")?.capitalizedString)! as String 

上面的代碼真實返回一個錯誤。這是錯誤,

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) 

回答

3

貌似你試圖設置在後臺線程文本(可能Web請求的完成處理程序)。當你更新UI元素時,你只能在主線程中這樣做。因此請確保您在更新UITextView時更新了主屏幕:

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

它工作正常!謝謝你的時間!這是信息! – suisied