【发布时间】:2012-02-23 10:33:28
【问题描述】:
我正在尝试从回调块中推送视图控制器。我要推送的视图控制器包含一个 UIWebView,它抱怨我应该在主线程上调用它。我尝试使用 NSInvocation 无济于事。如何在主线程上调用presentModalViewController:animated?
[vc requestUserPermissionWithCallback:^(BOOL inGranted)
{
if (inGranted)
{
if (serviceType == PXServiceTypeTwitter)
{
//[ad.rootViewController presentModalViewController:vc animated: YES]; // crashes
NSInvocation *invocation = [NSInvocation invocationWithTarget:ad.rootViewController selector:@selector(presentModalViewController:animated:) retainArguments:YES, vc, YES];
[invocation invokeOnMainThreadWaitUntilDone:NO]; // same result
}
}
else
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
}];
错误信息:
bool _WebTryThreadLock(bool), 0x6b21090: 试图从主线程或web线程以外的线程获取web lock。这可能是从辅助线程调用 UIKit 的结果。现在崩溃了...
我正在使用类别NSInvocation+CWVariableArguments。
【问题讨论】:
标签: objective-c multithreading uiwebview objective-c-blocks nsinvocation