Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be

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.

原因:在子线程中对UI进行了操作。

NSDate *startTime = [NSDate date];

    dispatch_async(dispatch_get_global_queue(0, 0), ^{

        NSString *fetchedData = [self fetchSomethingFromServer];

        NSString *processedData = [self processData:fetchedData];

        NSString *firstResult = [self calculateFirstResult:processedData];

        NSString *secondResult = [self calculateSecondResult:processedData];

        NSString *resultsSummary = [NSString stringWithFormat:@"First: [%@]\nSecond: [%@]",

                                    firstResult, secondResult];

        dispatch_async(dispatch_get_main_queue(), ^{

            [resultTextView setText:resultsSummary];    // *** UI操作放到主线程中执行 ***

        });

        NSDate *endTime = [NSDate date];

        NSLog(@"Completed in %f seconds", [endTime timeIntervalSinceDate:startTime]);

    });



你可能感兴趣的:(Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be)