Skip to content

Commit

Permalink
fix ui update not in main_thread crash
Browse files Browse the repository at this point in the history
  • Loading branch information
shockcao committed Dec 28, 2016
1 parent 5424f5f commit 0ca674f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion samples/iOS/iOSDemo/iOSDemo/MessageItemsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ - (int)notifyUIWithResponse:(NSData*)responseData {
self->converSations = convlstResponse.list;
LOG_INFO(kModuleViewController, @"recv conversation list, size: %lu", (unsigned long)[self->converSations count]);

[self.tableView reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});

return [self->converSations count] > 0 ? 0 : -1;

Expand Down
11 changes: 9 additions & 2 deletions samples/iOS/iOSDemo/iOSDemo/TopicViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,22 @@ - (IBAction)sendMessage:(id)sender forEvent:(UIEvent *)event {
[[NetworkService sharedInstance] startTask:sendMsgCGI ForUI:self];

self->text = _textField.text;
[_contentField setText:self->text];

dispatch_async(dispatch_get_main_queue(), ^{
[_contentField setText:self->text];
});
[_textField setText:@""];
}

- (void)notifyPushMessage:(NSData*)pushData withCmdId:(int)cmdId {
MessagePush* messagePush = [MessagePush parseFromData:pushData];
if (messagePush != nil) {
NSString* recvtext = [NSString stringWithFormat:@"%@ : %@", messagePush.pb_from, messagePush.content];
[_recvContentField setText:recvtext];
dispatch_queue_t mainQueue = dispatch_get_main_queue();
dispatch_async(mainQueue, ^{
[_recvContentField setText:recvtext];
});

}
}

Expand Down

0 comments on commit 0ca674f

Please sign in to comment.