简体   繁体   中英

iOS NSOperation subclass freezes device rotation on execution

I need your help. I have write my own custom NSOperation class called GetNewsOperation. I call it like this:

GetNewsOperation *getNewsOperation = [[GetNewsOperation alloc] initWithLocalNewsCategories:self];
[loadNewsOperationQueue addOperation:getNewsOperation];
[getNewsOperation release];

In GetNewsOperation class I have implemented init method for initialization and main method for executing operation and returning data back to the main thread.

Main method looks like this:

- (void)main {
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

    AppSettingsController *sharedAppSettingsController = [AppSettingsController sharedAppSettingsController];

    if( [type isEqualToString:@"getCategory"] ) {
        NSMutableArray *parsedData = [[NSMutableArray alloc] initWithArray:[sharedAppSettingsController getLocalNewsCategories]];

        [newsViewController performSelectorOnMainThread:@selector(loadDataResponse:) withObject:[NSArray arrayWithObjects:parsedData, nil] waitUntilDone:NO];

        [parsedData release]; parsedData = nil;
    }

    [pool release];
}

Everything works fine but I have a minor problem. When this operation is called application does not rotate on device orientation change. It changes after operation is finished.

As far as I know this operation is running for sure in new thread (not in main) cos all other elements in the app are active (not freezed). But I have only problem with orientation. The app looks kind a crappy if application does not rotate only when this operation occurs...

How can I solve this?

Thanks!

Actually it works like predicted. I was doing something else on main thread that blocked application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM