views:

24

answers:

1

Hi there, my main UIViewController should check for some data updates when it loads, if any update is found an opaque subview is added to show progress and so on.

Let's say that the method is called checkUpdates, so in my app delegate i do the following:

[window addSubview:viewController.view];
[window makeKeyAndVisible];

[viewController checkUpdates];

The method is like

- (void) checkUpdates {
    // add the opaque progress view
    [self.view addSubview:progress.view];
    [progress setMessage: @"Checking for updates ..."];

    // ... perform the update ...

    // remote the progress view
    [progress.view removeFromSuperview];
}

Theoretically the view should load and the update process should be seen, but the problem is that the view just get freezed during this phase, and when the update process is finished i'm able to interact with it.

Any idea?

A: 

Since the UI runs on the main thread of the app, if you perform "work" tasks on the main thread, you will also block the UI, which will therefore look frozen.

You might want to consider using NSOperationQueue or something equivalent to spin off another thread to do your work so the UI can continue to process updates independently.

Shaggy Frog
If i try to use NSOperationQueue, therefore a NSThread, i get 'message sent to deallocate instance' if i try to access a member of the app delegate inside the thread :S
Simone Margaritelli
@Simone Margaritelli Then you're doing something wrong. But that has nothing to do with using `NSOperationQueue` or some other thread-related feature *per se*. My answer stands: you can't do "work" tasks on the main thread, since you'll block the UI. There's no other type of solution to your problem.
Shaggy Frog
Ok, gonna solve it, tnx :)
Simone Margaritelli