-2

我需要在视图控制器中使用多个UIWebView,但在启动应用程序几分钟后,它会因为LoadRequest.

我在这里找到了这个代码块,UIWebViewDelegate但我无法成功地将它转换为 C#。

-(void)spinlockedWebViewLoad:(NSArray*)arr {
  NSAutoreleasePool* pool=[[NSAutoreleasePool alloc] init];
  UIWebView* webView=(UIWebView*)[arr objectAtIndex:0];
  NSURLRequest* request=(NSURLRequest*)[arr objectAtIndex:1];
  @synchronized(self) {
  spinlock=webView;
  [webView loadRequest:request];
  while (spinlock==webView) [NSThread sleepForTimeInterval:0.1];
  }
  [pool drain];
 }

-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
  if (spinlock!=webView) {
     [NSThread detachNewThreadSelector:@selector(spinlockedWebViewLoad:) toTarget:self withObject:[NSArray arrayWithObjects:webView,request,nil]];
     return NO;
  }
  return YES;
}
4

1 回答 1

0

在您的代码中,无需使用(ObjectiveC 风格)委托,只需使用托管事件:

void SpinlockedWebViewLoad (NSObject [] arr)
{
    ...
    UIWebView webView  = (UIWebView) arr [0];
    webView.ShouldStartLoad += ShouldStartLoad;
    ...
}

bool ShouldStartLoad (UIWebView webView, NSUrlRequest FileWebRequest, UIWebViewNavigationType navigationType)
{
    ...
}
于 2012-09-17T09:26:20.003 回答