Console: Fixed UITextView creation on non UI thread

This commit is contained in:
manuroe 2015-01-16 11:07:25 +01:00
parent 6ebbc6ebc2
commit d6dab31b5c

View file

@ -235,15 +235,15 @@ static NSAttributedString *messageSeparator = nil;
if (_messageType == RoomMessageTypeText) {
if (self.attributedTextMessage.length) {
// Use a TextView template to compute cell height
UITextView *dummyTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, _maxTextViewWidth, MAXFLOAT)];
// The following code only run on the main thread
if([NSThread currentThread] != [NSThread mainThread]) {
dispatch_sync(dispatch_get_main_queue(), ^{
UITextView *dummyTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, _maxTextViewWidth, MAXFLOAT)];
dummyTextView.attributedText = self.attributedTextMessage;
_contentSize = [dummyTextView sizeThatFits:dummyTextView.frame.size];
});
} else {
UITextView *dummyTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, _maxTextViewWidth, MAXFLOAT)];
dummyTextView.attributedText = self.attributedTextMessage;
_contentSize = [dummyTextView sizeThatFits:dummyTextView.frame.size];
}