告诉我如何在主队列上执行方法
我有3个metods缩放html,后缩放隐藏的WebView
- (void)updateContentWidth
{
[self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"setContentWidth('%d%%')", (int)(self.articleContentWidth*100)]];
}
- (void)updateLineHeight
{
[self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"setLineHeight('%d%%')", (int)(self.articleLineHeight*100)]];
}
- (void)updateFontSize
{
[self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"setFontSize('%d%%')", (int)(self.fontSizeRatio*100)]];
}
答案 0 :(得分:0)
使用下面的代码,你可以在主线程中调用任何方法或块:
dispatch_sync(dispatch_get_main_queue(), ^{
// write or call method here
});
答案 1 :(得分:0)
试试这个
[self performSelectorOnMainThread:@selector(updateContentWidth)
withObject:nil
waitUntilDone:YES/NO-To block/not block the current thread];