Iphone 如何在新视图类的不同线程上加载UIWebview?对象前';s presentModalViewController被调用?

Iphone 如何在新视图类的不同线程上加载UIWebview?对象前';s presentModalViewController被调用?,iphone,objective-c,ios,uiwebview,uikit,Iphone,Objective C,Ios,Uiwebview,Uikit,翻阅坠机报告 This GDB was configured as "x86_64-apple-darwin".Attaching to process 1798. 2012-05-17 13:19:59.628 PDFView[1798:11603] bool _WebTryThreadLock(bool), 0x684b940: Tried to obtain the web lock from a thread other than the main thread or the w

翻阅坠机报告

This GDB was configured as "x86_64-apple-darwin".Attaching to process 1798.
    2012-05-17 13:19:59.628 PDFView[1798:11603] bool _WebTryThreadLock(bool), 0x684b940: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
    1   WebThreadLock
    [Switching to process 1798 thread 0x11603]
    2   -[UIWebView _webViewCommonInit:]
    3   -[UIWebView initWithCoder:]
    4   _decodeObjectBinary
    5   _decodeObject
    6   -[UIRuntimeConnection initWithCoder:]
    7   _decodeObjectBinary
    8   -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:]
    9   -[NSArray(NSArray) initWithCoder:]
    10  _decodeObjectBinary
    11  _decodeObject
    12  -[UINib instantiateWithOwner:options:]
    13  -[UIViewController _loadViewFromNibNamed:bundle:]
    14  -[UIViewController loadView]
    15  -[UIViewController view]
    16  -[UIViewController viewControllerForRotation]
    17  -[UIViewController _visibleView]
    18  -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:]
    19  -[UIViewController presentViewController:withTransition:completion:]
    20  -[UIViewController presentViewController:animated:completion:]
    21  -[UIViewController presentModalViewController:animated:]
    22  -[LoginPageVC loadVC]
    23  __invoking___
    24  -[NSInvocation invoke]
    25  -[NSInvocationOperation main]
    26  -[__NSOperationInternal start]
    27  -[NSOperation start]
    28  [Switching to process 1798 thread 0x11603]
    __block_global_6
    29  _dispatch_call_block_and_release
    30  _dispatch_worker_thread2
    31  _pthread_wqthread
    sharedlibrary apply-load-rules all
    Current language:  auto; currently objective-c
我认为我得到了这个错误,这是由于webview在另一个线程而不是主线程上加载请求。我想在后台加载web视图,以避免UI阻塞

//调用其他视图控制器

{
 ViewController* objVC=[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];        

NSString* PDFURLString = @"http://images.apple.com/xserve/pdf/L422277A_Xserve_Guide.pdf";

 //creating diff thread.....

NSOperationQueue *queue = [NSOperationQueue new];

 // create own NSInvocation Operation to call other function of other view controller class

NSInvocationOperation * operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(loadURL) object:PDFURLString];    

// add operation to queue

    [queue addOperation:operation];
    [operation release];        

    [self presentModalViewController:objVC animated:YES];

}
//这是ObjVC调用的函数

-(void)loadURl:(NSString*)urlString
{

    [_indicator startAnimating];
    NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:_PDFURLString]];    
    NSLog(@"loading URL DATA");
    //Store the Data locally as PDF File

    NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle]  resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];

    _filePath = [resourceDocPath stringByAppendingPathComponent:@"myPDF.pdf"];
    NSLog(@"File Path:%@",_filePath);

    [pdfData writeToFile:_filePath atomically:YES];


    //Now create Request for the file that was saved in your documents folder

    NSURL *url = [NSURL fileURLWithPath:_filePath];

    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    [_webView setUserInteractionEnabled:YES];

    _webView.scalesPageToFit = YES;

    [_webView setDelegate:self];

    [_webView loadRequest:requestObj];

}
请查看我的代码,并建议在不同线程上加载web视图的最佳方法,同时UI会做出响应。
谢谢。

加载请求:方法已经异步执行,因此从主线程调用它不会在加载过程中阻塞UI。

加载请求:方法已经异步执行,因此从主线程调用它不会在加载过程中阻塞UI。

它是描述NSOperationQueue。还请说明要加载的web视图。谢谢它是描述NSOperationQueue的有用站点。还请说明要加载的web视图。谢谢。嗨,谢谢你帮助@Phillip,但是当调用新的ViewController(VC)类时,UI被阻塞了。可能是在从url加载下一个VC的请求时。我正在使用UISegment再次加载网页,其中包含名为VC的新url。NSInvocationOperation*操作=[[NSInvocationOperation alloc]initWithTarget:自选择器:@selector(loadURl:)对象:PDFURLString];它与上述功能配合良好。但是我想在调用web视图的ViewController时,它不应该在加载下一个调用的VC时挂起UI。嗨,谢谢@Phillip的帮助,但是当调用新的ViewController(VC)类时,UI被阻塞了。可能是在从url加载下一个VC的请求时。我正在使用UISegment再次加载网页,其中包含名为VC的新url。NSInvocationOperation*操作=[[NSInvocationOperation alloc]initWithTarget:自选择器:@selector(loadURl:)对象:PDFURLString];它与上述功能配合良好。但是我想在调用web视图的ViewController时,它不应该在加载下一个调用的VC时挂起UI。