iosobjective-cmultithreadingdelegatesmodalviewcontroller

Why would a simple modal view controller lag when presented and dismissed?


The main view of my app is a UIImagePickerController camera view. When the app becomes active (in didBecomeActive), I present a modal view controller that shows some settings generated from a network request. (Note that for debugging purposes, I took the network request out and am currently just showing a dummy view)

The modal view animates in smoothly, but after loading it freezes for 3 seconds then responds normally. After dismissing the view (also animates smoothly), my image picker controller pauses for 2 seconds then resumes normally.

I have removed all functionality from the modal view controller to make sure there was no operations clogging the main thread. I am presenting the most basic of controllers, and still get the choppy ui. I would suspect that this is from my presenting view controller calling viewDidLoad/Unload or something similar, but my search did not give me any information on what delegate methods are called in the presenting view controller when a modal view is shown.

My problem can be solved by answering:


Solution

  • This is probably because you are making a lot of processing in the main thread (usually when UI stops, it's because main thread processing). Try to provide us some code, specifically the one you think is the most heavy processing code! Sorry about my poor english :P! Try dispatching most heavy code to another thread with

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        //your heavy code here =)
    });
    

    Regards, Lucas