Skip to content

Commit c273a69

Browse files
committed
Update JSCallOCViewController.m
1 parent 0cbc5a9 commit c273a69

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

JavaScriptCore-Demo/JSCallOC/JSCallOCViewController.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView
7272
self.context[@"alert"] =
7373
^(NSString *str)
7474
{
75-
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"msg from js" message:str delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
76-
[alert show];
75+
//要把改变视图的操作放到主线程中,否则就会抛出异常,对以后的操作会有问题
76+
[[NSOperationQueue mainQueue]addOperationWithBlock:^{
77+
78+
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
79+
[alert show];
80+
}];
7781
};
7882

7983
__block typeof(self) weakSelf = self;

0 commit comments

Comments
 (0)